Firebase Utilities
Simple utilities to reduce some firebase-admin
tasks.
Overview
getFirebaseAdmin(credential, realtimeDbUrl)
Easy function to initialize firebase-admin
only once.
validateToken(token, firebaseAdminInstance)
Validates an idToken generated by Firebase Auth (not access token, idToken).
Also supports the format Bearer <token>
or just <token>
getTestIdToken(firebaseAdminInstance, userId, claims)
Gets an Id Token from the Firebase Emulator.
Usage
An example of using all three tools
import { getFirebaseAdmin, validateToken, getTestIdToken } from '@anatine/firebase-utils'
const admin = getFirebaseAdmin();
const uid = 'SomeUserId'
const { idToken } = await getTestIdToken({admin, uid, claims: {status: 'this is awesome'}})
const decodedUserData = await validateToken(idToken, admin)
console.log(decodedUserData)