Skip to content
Open
Show file tree
Hide file tree
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
Next Next commit
Add customUserClaims to UpdateRequest
  • Loading branch information
brettwillis committed Aug 22, 2022
commit 59d329be74b4da0a0521214630fac94939eadae0
19 changes: 18 additions & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ export abstract class AbstractAuthRequestHandler {
if (customUserClaims === null) {
customUserClaims = {};
}
// Construct custom user attribute editting request.
// Construct custom user attribute editing request.
const request: any = {
localId: uid,
customAttributes: JSON.stringify(customUserClaims),
Expand Down Expand Up @@ -1405,6 +1405,13 @@ export abstract class AbstractAuthRequestHandler {
'providersToUnlink of properties argument must be an array of strings.');
}
});
} else if ((typeof properties.customUserClaims !== 'undefined') && !validator.isObject(properties.customUserClaims)) {
return Promise.reject(
new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
'customUserClaims of properties argument must be an object, null, or undefined.',
),
);
}

// Build the setAccountInfo request.
Expand Down Expand Up @@ -1470,6 +1477,16 @@ export abstract class AbstractAuthRequestHandler {
request.disableUser = request.disabled;
delete request.disabled;
}
// Rewrite customClaims to customAttributes
if (typeof request.customUserClaims !== 'undefined') {
if (request.customUserClaims === null) {
// Delete operation. Replace null with an empty object.
request.customAttributes = JSON.stringify({});
} else {
request.customAttributes = JSON.stringify(request.customUserClaims);
}
delete request.customUserClaims;
}
// Construct mfa related user data.
if (validator.isNonNullObject(request.multiFactor)) {
if (request.multiFactor.enrolledFactors === null) {
Expand Down
6 changes: 6 additions & 0 deletions src/auth/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export interface UpdateRequest {
* Unlinks this user from the specified providers.
*/
providersToUnlink?: string[];

/**
* If provided, sets additional developer claims on the user's token, overwriting
* any existing claims. If not provided or `undefined`, then existing claims will remain unchanged.
*/
customUserClaims?: object | null;
}

/**
Expand Down