Created
January 16, 2022 04:49
-
-
Save colinfwren/fb58446055130cd2ffdd67918907bc8b to your computer and use it in GitHub Desktop.
A Firebase function that will create data and return a JWT for the userId to aid with testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as admin from "firebase-admin"; | |
import axios from "axios"; | |
admin.initializeApp(); | |
const auth = admin.auth(); | |
const FIREBASE_TOKEN = 'This can be found in the firebase console under Web API Key on the settings page' | |
exports.createTestDataForUser = functions.https.onRequest(async (req, res) => { | |
const {uid} = req.body; | |
try { | |
await createNewUserMap(uid, db); // Function to seed data | |
const token = await auth.createCustomToken(uid); | |
const authResult: any = await axios.post( | |
`http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=${FIREBASE_TOKEN}`, | |
{ | |
token, | |
returnSecureToken: true, | |
} | |
); | |
res.status(201).json({ | |
token: authResult.data.idToken, | |
}); | |
} catch (err: any) { | |
res.json({ | |
error: err.message, | |
}); | |
} | |
return; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment