Created
September 4, 2019 10:13
-
-
Save shark-h/049fcca74d58c06844e55adfb4810318 to your computer and use it in GitHub Desktop.
This file contains 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
// REGISTER USER WITH REQUIRED CUSTOM CLAIMS | |
exports.registerUser = functions.https.onCall(async (data, context) => { | |
const email = data.email; | |
const password = data.password; | |
const displayName = data.displayName; | |
if (email == null || password == null || displayName == null) { | |
throw new functions.https.HttpsError('signup-failed', 'missing information'); | |
} | |
try { | |
var userRecord = await admin.auth().createUser({ | |
email: email, | |
password: password, | |
displayName: displayName | |
}); | |
const customClaims = { | |
"https://hasura.io/jwt/claims": { | |
"x-hasura-default-role": "user", | |
"x-hasura-allowed-roles": ["user"], | |
"x-hasura-user-id": userRecord.uid | |
} | |
}; | |
await admin.auth().setCustomUserClaims(userRecord.uid, customClaims); | |
return userRecord.toJSON(); | |
} catch (e) { | |
throw new functions.https.HttpsError('signup-failed', JSON.stringify(error, undefined, 2)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment