Home > Enterprise >  context.auth.token.email_verified in https callable Firebase function is false despite verification
context.auth.token.email_verified in https callable Firebase function is false despite verification

Time:11-19

I am trying to prevent users with an unverified email from executing a cloud function. My function looks like this :

export const myFunction = functions.https.onCall(async (data, context) => {
  if (context.auth && context.auth.token.email_verified) {
    //my actual function code
  } else {
    if (!context.auth) {
      functions.logger.log("unauthenticated call to myFunction");
    } else if (!context.auth.token.email_verified) {
      functions.logger.log("unverified email call to myFunction with token", context.auth.token);
    }
  }
});

I'm calling this function from my react-native frontend app this way :

const myFunction = firebase.functions().httpsCallable("myFunction");
myFunction(payload);

I went through the email verification process by clicking the link I received, and everything seemed to work fine. If I log my current user from my frontend app, the emailVerified prop is true :

console.log(firebase.auth().currentUser)

However, when calling the cloud function, it logs unverified email call to myFunction with token, and the email_verified prop is false inside the token

Am I missing something ? How can the two be different ?

CodePudding user response:

Problem comes from token refreshing and is similar to https://stackoverflow.com/a/47281903/6353365

  • Related