Back to Firebase Js Sdk

User interface

docs-devsite/auth.user.md

12.12.16.0 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

User interface

A user account.

<b>Signature:</b>

typescript
export interface User extends UserInfo 

<b>Extends:</b> UserInfo

Properties

PropertyTypeDescription
emailVerifiedbooleanWhether the email has been verified with sendEmailVerification() and applyActionCode()<!-- -->.
isAnonymousbooleanWhether the user is authenticated using the ProviderId<!-- -->.ANONYMOUS provider.
metadataUserMetadataAdditional metadata around user creation and sign-in times.
providerDataUserInfo<!-- -->[]Additional per provider such as displayName and profile information.
refreshTokenstringRefresh token used to reauthenticate the user. Avoid using this directly and prefer User.getIdToken() to refresh the ID token instead.
tenantIdstring | nullThe user's tenant ID.

Methods

MethodDescription
delete()Deletes and signs out the user.
getIdToken(forceRefresh)Returns a JSON Web Token (JWT) used to identify the user to a Firebase service.
getIdTokenResult(forceRefresh)Returns a deserialized JSON Web Token (JWT) used to identify the user to a Firebase service.
reload()Refreshes the user, if signed in.
toJSON()Returns a JSON-serializable representation of this object.

User.emailVerified

Whether the email has been verified with sendEmailVerification() and applyActionCode()<!-- -->.

<b>Signature:</b>

typescript
readonly emailVerified: boolean;

User.isAnonymous

Whether the user is authenticated using the ProviderId<!-- -->.ANONYMOUS provider.

<b>Signature:</b>

typescript
readonly isAnonymous: boolean;

User.metadata

Additional metadata around user creation and sign-in times.

<b>Signature:</b>

typescript
readonly metadata: UserMetadata;

User.providerData

Additional per provider such as displayName and profile information.

<b>Signature:</b>

typescript
readonly providerData: UserInfo[];

User.refreshToken

Refresh token used to reauthenticate the user. Avoid using this directly and prefer User.getIdToken() to refresh the ID token instead.

<b>Signature:</b>

typescript
readonly refreshToken: string;

User.tenantId

The user's tenant ID.

This is a read-only property, which indicates the tenant ID used to sign in the user. This is null if the user is signed in from the parent project.

<b>Signature:</b>

typescript
readonly tenantId: string | null;

Example

javascript
// Set the tenant ID on Auth instance.
auth.tenantId = 'TENANT_PROJECT_ID';

// All future sign-in request now include tenant ID.
const result = await signInWithEmailAndPassword(auth, email, password);
// result.user.tenantId should be 'TENANT_PROJECT_ID'.

User.delete()

Deletes and signs out the user.

Important: this is a security-sensitive operation that requires the user to have recently signed in. If this requirement isn't met, ask the user to authenticate again and then call one of the reauthentication methods like reauthenticateWithCredential()<!-- -->.

This method is not supported on any User signed in by Auth instances created with a FirebaseServerApp<!-- -->.

<b>Signature:</b>

typescript
delete(): Promise<void>;

<b>Returns:</b>

Promise<void>

User.getIdToken()

Returns a JSON Web Token (JWT) used to identify the user to a Firebase service.

Returns the current token if it has not expired or if it will not expire in the next five minutes. Otherwise, this will refresh the token and return a new one.

<b>Signature:</b>

typescript
getIdToken(forceRefresh?: boolean): Promise<string>;

Parameters

ParameterTypeDescription
forceRefreshbooleanForce refresh regardless of token expiration.

<b>Returns:</b>

Promise<string>

User.getIdTokenResult()

Returns a deserialized JSON Web Token (JWT) used to identify the user to a Firebase service.

Returns the current token if it has not expired or if it will not expire in the next five minutes. Otherwise, this will refresh the token and return a new one.

<b>Signature:</b>

typescript
getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;

Parameters

ParameterTypeDescription
forceRefreshbooleanForce refresh regardless of token expiration.

<b>Returns:</b>

Promise<IdTokenResult<!-- -->>

User.reload()

Refreshes the user, if signed in.

<b>Signature:</b>

typescript
reload(): Promise<void>;

<b>Returns:</b>

Promise<void>

User.toJSON()

Returns a JSON-serializable representation of this object.

<b>Signature:</b>

typescript
toJSON(): object;

<b>Returns:</b>

object

A JSON-serializable representation of this object.