Home > OS >  Firestore with service account
Firestore with service account

Time:07-12

I'm building a react native app (expo managed) and want to authenticate users using a phone number. To do so I need to convert the token I receive from Magic to a JWT. I'm unsure how to enable the service account. I have the private key, but it seems like I need to initialize the app using the same method I used to initialize firestore. Or can I combine the two keys?

Thanks!

CodePudding user response:

The auth Cloud Function takes in the DID token and converts it into a Firebase user access token. Pass the Firebase user access token into the firebase.auth().signInWithCustomToken method to authenticate user natively with Firebase.

Magic doesn't replace Firebase Auth, and can actually integrate seamlessly into it so you will be able to have the same permissions and database rules configurations as if it's native Firebase Auth.

User logs in with Magic link, which upon successful login, generates a DID token The DID token is passed into the auth Firebase httpsCallable Cloud Function. The auth Cloud Function takes in the DID token and converts it into a Firebase user access token Pass the Firebase user access token into the firebase.auth().signInWithCustomToken method to authenticate user natively with Firebase

/* User login with Magic link to get DID token */
   const didToken = await magic.auth.loginWithMagicLink({ email });
   const auth = firebase.functions().httpsCallable("auth");

/* DID token is passed into the auth callable function */
   let result = (await auth({ didToken })).data;

/* Firebase user access token is used to authenticate */
   await firebase.auth().signInWithCustomToken(result.token);

You can follow this step for Implement Auth Callable Function in this link. This will help you to convert your Magic DID token into a Firebase user access token.

  • Related