Skip to content

Instantly share code, notes, and snippets.

@shark-h
Created September 4, 2019 10:13
Show Gist options
  • Save shark-h/049fcca74d58c06844e55adfb4810318 to your computer and use it in GitHub Desktop.
Save shark-h/049fcca74d58c06844e55adfb4810318 to your computer and use it in GitHub Desktop.
// 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