Last active
August 3, 2020 07:48
-
-
Save shark-h/d1775b9c34c6b5156c4adf9e7b1d7a5a to your computer and use it in GitHub Desktop.
Get user data from Firebase
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
const functions = require("firebase-functions"); | |
const admin = require("firebase-admin"); | |
admin.initializeApp(functions.config().firebase); | |
// On sign up. | |
exports.processSignUp = functions.auth.user().onCreate(user => { | |
const customClaims = { | |
"https://hasura.io/jwt/claims": { | |
"x-hasura-default-role": "user", | |
"x-hasura-allowed-roles": ["user"], | |
"x-hasura-user-id": user.uid | |
} | |
}; | |
return admin | |
.auth() | |
.setCustomUserClaims(user.uid, customClaims) | |
.then(() => { | |
// Update real-time database to notify client to force refresh. | |
const metadataRef = admin.database().ref("metadata/" + user.uid); | |
// Set the refresh time to the current UTC timestamp. | |
// This will be captured on the client to force a token refresh. | |
return metadataRef.set({ refreshTime: new Date().getTime() }); | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment