Skip to content

Add a resaturation function for auth User instances #4484

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages-exp/auth-exp/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export {
export { getIdToken, getIdTokenResult } from './user/id_token_result';
export { unlink } from './user/link_unlink';
export { getAdditionalUserInfo } from './user/additional_user_info';
export { userFromJSON } from './user/user_impl';

// Non-optional user methods.
export { reload } from './user/reload';
Expand Down
5 changes: 5 additions & 0 deletions packages-exp/auth-exp/src/core/user/user_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FinalizeMfaResponse } from '../../api/authentication/mfa';
import { Auth } from '../../model/auth';
import { IdTokenResponse } from '../../model/id_token';
import { MutableUserInfo, User, UserParameters } from '../../model/user';
import { _castAuth } from '../auth/auth_impl';
import { AuthErrorCode } from '../errors';
import { PersistedBlob } from '../persistence';
import { _assert } from '../util/assert';
Expand Down Expand Up @@ -317,3 +318,7 @@ export class UserImpl implements User {
return user;
}
}

export function userFromJSON(auth: externs.Auth, json: string): externs.User {
return UserImpl._fromJSON(_castAuth(auth), JSON.parse(json));
Copy link
Contributor

@jacksteamdev jacksteamdev Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful if this could take a plain object as well (some storage solutions parse the JSON automatically), for example:

const userObj = typeof json === "string" ? JSON.parse(json) : json;
return UserImpl._fromJSON(_castAuth(auth), userObj);

}