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

Typescript error when trying to use an async function for signInSuccessWithAuthResult callback #1056

Open
emwadde opened this issue Dec 6, 2023 · 1 comment

Comments

@emwadde
Copy link

emwadde commented Dec 6, 2023

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 22.04
  • Browser version: Chrome 120.0.6099.62 (Official Build) beta (64-bit)
  • Firebase UI version: 6.1.0
  • Firebase SDK version: 10.7

[REQUIRED] Describe the problem

The interface for signInSuccessWithAuthResult callback currently is set to boolean at line 26 of types/index.d.ts.
As a result, typescript throws: Type 'Promise' is not assignable to type 'boolean' if the callback function is an async function.

Steps to reproduce:

set the uiConfig.callbacks.signInSuccessWithAuthResult to an async function

Relevant Code:

/**
 * @param  {import('firebase/auth').UserCredential} authResult
 * */
const signInSuccessCallback = async (authResult) => {
    const token = await authResult.user.getIdToken()
    console.log(token)
    return true
};

/**@type {import('firebaseui').auth.Config}*/
var uiConfig = {
    callbacks: {
        signInSuccessWithAuthResult: signInSuccessCallback
    },
    signInOptions: [{
        provider: GoogleAuthProvider.PROVIDER_ID,
        customParameters: {
            prompt: 'select_account'
        }
    }],
    signInFlow: 'popup',
    tosUrl: '/tos',
    privacyPolicyUrl: '/tos'
}

Workaround/Fix:

The issue is resolved by updating the Callback interface to include Promise<boolean> as a type for signInSuccessWithAuthResult

interface Callbacks {
  signInSuccessWithAuthResult?(
    // tslint:disable-next-line:no-any firebase dependency not available.
    authResult: any,
    redirectUrl?: string
  ): Promise<boolean>|boolean;  
  signInFailure?(error: firebaseui.auth.AuthUIError): Promise<void>|void;
  uiShown?(): void;
}
@jhuleatt
Copy link
Collaborator

Hi @emwadde, the types in types/index.d.ts are correct in this case - FirebaseUI doesn't expect a function that returns a promise that resolves to a boolean, it expects a function that returns a boolean (docs).

This would be a breaking change in FirebaseUI, so I'll leave it open as a feature request. If you'd like to provide more context on your use case (seems like you might be trying to get the JWT for a custom auth integration?), or if others would like to chime in, it would give us a better idea about whether we should prioritize this change.

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

No branches or pull requests

2 participants