Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase UI signInSuccessWithAuthResult asynchronous

I tried to use asynchronous code in the signInSuccessWithAuthResult of the Firebase UI in order to perform a conditional redirect but it always fails respectively my asynchronous code is not run and my redirect is ignored.

Are you able to use asynchronous code in signInSuccessWithAuthResult? Or do I do something wrong?

const uiConfig = {
            signInFlow: 'redirect',
            signInSuccessUrl: appUrl,
            signInOptions: signInOptions,
            tosUrl: appUrl + '/terms',
            privacyPolicyUrl: appUrl + '/privacy',
            credentialHelper: firebaseui.auth.CredentialHelper.GOOGLE_YOLO,
            autoUpgradeAnonymousUsers: true,
            callbacks: {
                signInSuccessWithAuthResult: async (_authResult, _redirectUrl) => {
                    await this.navigateRedirect();

                    return false;
                },
                signInFailure: this.onSignInFailure
            }
        };

private async navigateRedirect() {
     const redirectUrl: string = await get<string>('deckdeckgo_redirect');

    window.location.assign(redirectUrl);
}

I use firebaseui v4.0.0. and the above get used idb-keyval.

like image 359
David Dal Busco Avatar asked Oct 17 '25 16:10

David Dal Busco


1 Answers

The signInSuccessWithAuthResult callback expects a synchronous function. Change to the following:

callbacks: {
  signInSuccessWithAuthResult: (_authResult, _redirectUrl) => {
    // This will run asynchronously. When it resolves, it will complete the
    // redirect.
    this.navigateRedirect();
    // In the meantime, disable FirebaseUI redirect.
    return false;
  },
},
like image 62
bojeil Avatar answered Oct 20 '25 07:10

bojeil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!