0
0
Firebasecloud~30 mins

Custom authentication tokens in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Custom Authentication Tokens with Firebase
📖 Scenario: You are building a secure app that needs to verify users with custom authentication tokens. These tokens allow your app to trust users who sign in through your own system.
🎯 Goal: Create a Firebase Cloud Function that generates a custom authentication token for a user with a specific user ID and a role claim.
📋 What You'll Learn
Create a variable with the user ID
Create a configuration object with custom claims
Generate a custom token using Firebase Admin SDK
Return the generated token
💡 Why This Matters
🌍 Real World
Custom authentication tokens let your app securely identify users with roles or permissions you define. This is useful when you have your own user system outside Firebase.
💼 Career
Many cloud jobs require integrating custom authentication with Firebase or other identity providers to control user access securely.
Progress0 / 4 steps
1
Set up the user ID variable
Create a variable called uid and set it to the string 'user123'.
Firebase
Need a hint?

Use const to declare the user ID variable.

2
Create custom claims configuration
Create a constant called customClaims and set it to an object with a key role and value 'admin'.
Firebase
Need a hint?

Use an object literal to set the role claim.

3
Generate the custom authentication token
Use admin.auth().createCustomToken(uid, customClaims) to generate a custom token and assign it to a constant called customToken. Use await since this returns a promise.
Firebase
Need a hint?

Remember to use await because createCustomToken returns a promise.

4
Return the generated token
Return the customToken from the function.
Firebase
Need a hint?

Use the return keyword to send back the token.