File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,36 @@ admin.auth().getUser(uid).then((userRecord) => {
2929 // The claims can be accessed on the user record.
3030 console . log ( userRecord . customClaims . admin ) ;
3131} ) ;
32- // [END read_custom_user_claims]
32+ // [END read_custom_user_claims]
33+
34+ // [START set_custom_user_claims_script]
35+ admin . auth ( ) . getUserByEmail ( 'user@admin.example.com' ) . then ( ( user ) => {
36+ // Confirm user is verified.
37+ if ( user . emailVerified ) {
38+ // Add custom claims for additional privileges.
39+ // This will be picked up by the user on token refresh or next sign in on new device.
40+ return admin . auth ( ) . setCustomUserClaims ( user . uid , {
41+ admin : true
42+ } ) ;
43+ }
44+ } )
45+ . catch ( ( error ) => {
46+ console . log ( error ) ;
47+ } ) ;
48+ // [END set_custom_user_claims_script]
49+
50+ // [START set_custom_user_claims_incremental]
51+ admin . auth ( ) . getUserByEmail ( 'user@admin.example.com' ) . then ( ( user ) => {
52+ // Add incremental custom claim without overwriting existing claims.
53+ const currentCustomClaims = user . customClaims ;
54+ if ( currentCustomClaims . admin ) {
55+ // Add level.
56+ currentCustomClaims [ 'accessLevel' ] = 10 ;
57+ // Add custom claims for additional privileges.
58+ return admin . auth ( ) . setCustomUserClaims ( user . uid , currentCustomClaims ) ;
59+ }
60+ } )
61+ . catch ( ( error ) => {
62+ console . log ( error ) ;
63+ } ) ;
64+ // [END set_custom_user_claims_incremental]
You can’t perform that action at this time.
0 commit comments