[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth onCreate trigger doesn't trigger in emulators with magic link sign in flow #1565

Closed
pschoffer opened this issue May 14, 2024 · 2 comments

Comments

@pschoffer
Copy link

Related issues

[REQUIRED] Version info

node:

$ node --version
v18.17.1
firebase-functions: 5.0.1

firebase-tools:
$ firebase --version
13.7.2

**firebase-admin:**11.8.0

[REQUIRED] Test case

  1. Setup User function:
import * as v1Functions from 'firebase-functions/v1';

export const setupNewUser = v1Functions.region(region).auth.user().onCreate(async user => {
    const { uid, email } = user;
    await admin.firestore().collection(COLLECTIONS.USERS).doc(uid).set({ uid, email });
    v1Functions.logger.info(`New user: ${email} (${uid})`);
});
  1. Create user via link login:
    import { sendSignInLinkToEmail } from 'firebase/auth';
   ....
    const handleLogin = async (data: Inputs) => {
        const url = window.location.href + `?signinFinished=true`;
        await sendSignInLinkToEmail(auth, data.email, {
            url,
            handleCodeInApp: true
        });
    }
  1. user gets logged in and created in auth emulator. The emulator output:
⚠  canHandleCodeInApp is unsupported in Auth Emulator. All OOB operations will complete via web.
i  To sign in as schoffer.pavel@gmail.com, follow this link: http://127.0.0.1:9099/emulator/action?mode=signIn&lang=en&oobCode=ygnXe-FGeJbfOmrGaessvJzEVl-lwk-HKfZzllWG-8Kvkgm5mSreqY&apiKey=fake-api-key&continueUrl=http%3A%2F%2Flocalhost%3A3000%2Fbilling_plan%3Femail_signin_finished%3Dtrue

The user now exists in auth emulator:
image

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

Expected: setupNewUser function gets triggered.

[REQUIRED] Actual behavior

Actual: setupNewUser is not triggered.

Note: setupNewUser function gets triggered as expected if user is created via emulators UI directly as well in production once deployed. This issue seems to be limited to combination of auth emulators and login via link method.

Were you able to successfully deploy your functions?

Nope. All works correctly when deployed.

@pschoffer
Copy link
Author

I am happy to investigate further, but could use some pointers to how these triggers work under the hood.

@pschoffer
Copy link
Author

Oh my bad. I had an initEmulators script that ran too early for the functions to be bootstraped probably and that created the user in the first place not the sign in link. Ignore me:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant