Skip to content

Fix a small bug in setCustomUserClaims() auth snippet #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ public static void updateUser(String uid) throws FirebaseAuthException {
// [END update_user]
}

public static void setCustomUserClaims(
public static void setCustomUserClaims(TenantAwareFirebaseAuth tenantAuth,
String uid) throws FirebaseAuthException {
// [START set_custom_user_claims]
// Set admin privilege on the user corresponding to uid.
Map<String, Object> claims = new HashMap<>();
claims.put("admin", true);
FirebaseAuth.getInstance().setCustomUserClaims(uid, claims);
tenantAuth.setCustomUserClaims(uid, claims);
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
// [END set_custom_user_claims]
Expand All @@ -173,7 +173,7 @@ public static void setCustomUserClaims(

// [START read_custom_user_claims]
// Lookup the user associated with the specified uid.
UserRecord user = FirebaseAuth.getInstance().getUser(uid);
UserRecord user = tenantAuth.getUser(uid);
System.out.println(user.getCustomClaims().get("admin"));
// [END read_custom_user_claims]
}
Expand Down