-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,758 additions
and
944 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ jobs: | |
strategy: | ||
matrix: | ||
node-version: | ||
- 10.x | ||
- 12.x | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// [START auth_custom_claims_cloud_function] | ||
const functions = require('firebase-functions'); | ||
const { initializeApp } = require('firebase-admin/app'); | ||
const { getAuth } = require('firebase-admin/auth'); | ||
const { getDatabase } = require('firebase-admin/database'); | ||
|
||
initializeApp(); | ||
|
||
// On sign up. | ||
exports.processSignUp = functions.auth.user().onCreate(async (user) => { | ||
// Check if user meets role criteria. | ||
if ( | ||
user.email && | ||
user.email.endsWith('@admin.example.com') && | ||
user.emailVerified | ||
) { | ||
const customClaims = { | ||
admin: true, | ||
accessLevel: 9 | ||
}; | ||
|
||
try { | ||
// Set custom user claims on this newly created user. | ||
await getAuth().setCustomUserClaims(user.uid, customClaims); | ||
|
||
// Update real-time database to notify client to force refresh. | ||
const metadataRef = getDatabase().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. | ||
await metadataRef.set({refreshTime: new Date().getTime()}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
}); | ||
// [END auth_custom_claims_cloud_function] |
Oops, something went wrong.