in src/auth/auth-api-request.ts [313:362]
function validateProviderUserInfo(request: any): void {
const validKeys = {
rawId: true,
providerId: true,
email: true,
displayName: true,
photoUrl: true,
};
// Remove invalid keys from original request.
for (const key in request) {
if (!(key in validKeys)) {
delete request[key];
}
}
if (!validator.isNonEmptyString(request.providerId)) {
throw new FirebaseAuthError(AuthClientErrorCode.INVALID_PROVIDER_ID);
}
if (typeof request.displayName !== 'undefined' &&
typeof request.displayName !== 'string') {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_DISPLAY_NAME,
`The provider "displayName" for "${request.providerId}" must be a valid string.`,
);
}
if (!validator.isNonEmptyString(request.rawId)) {
// This is called localId on the backend but the developer specifies this as
// uid externally. So the error message should use the client facing name.
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_UID,
`The provider "uid" for "${request.providerId}" must be a valid non-empty string.`,
);
}
// email should be a string and a valid email.
if (typeof request.email !== 'undefined' && !validator.isEmail(request.email)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_EMAIL,
`The provider "email" for "${request.providerId}" must be a valid email string.`,
);
}
// photoUrl should be a URL.
if (typeof request.photoUrl !== 'undefined' &&
!validator.isURL(request.photoUrl)) {
// This is called photoUrl on the backend but the developer specifies this as
// photoURL externally. So the error message should use the client facing name.
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_PHOTO_URL,
`The provider "photoURL" for "${request.providerId}" must be a valid URL string.`,
);
}
}