Class User<UserFunctionsFactoryType, UserCustomDataType, UserProfileDataType>

Representation of an authenticated user of an App.

Type Parameters

Constructors

Accessors

  • get accessToken(): null | string
  • The access token used when requesting a new access token.

    Returns null | string

    The access token as a string or null.

  • get apiKeys(): ApiKeyAuth
  • Perform operations related to the API-key auth provider.

    Returns ApiKeyAuth

    An ApiKeyAuth object that can be used to manage API keys.

  • get customData(): UserCustomDataType
  • You can store arbitrary data about your application users in a MongoDB collection and configure Atlas App Services to automatically expose each user’s data in a field of their user object. For example, you might store a user’s preferred language, date of birth, or their local timezone.

    If this value has not been configured, it will be empty.

    Returns UserCustomDataType

    The custom data as an object.

  • get deviceId(): null | string
  • The ID of the device.

    Returns null | string

    The device ID as a string or null.

  • get id(): string
  • The automatically-generated internal ID of the user.

    Returns string

    The user ID as a string.

  • get identities(): UserIdentity[]
  • The identities of the user at any of the app's authentication providers.

    Returns UserIdentity[]

    An array of UserIdentity objects.

  • get isLoggedIn(): boolean
  • The logged in state of the user.

    Returns boolean

    true if the user is logged in, false otherwise.

  • get profile(): UserProfileDataType
  • A profile containing additional information about the user.

    Returns UserProfileDataType

    The user profile data as an object.

  • get providerType(): ProviderType
  • The provider type used when authenticating the user. If multiple identities exist, the provider type for the first identity found is return.

    Returns ProviderType

    The provider type as an enumerated string.

    Deprecated

    Use identities instead.

  • get refreshToken(): null | string
  • The refresh token used when requesting a new access token.

    Returns null | string

    The refresh token as a string or null.

  • get state(): UserState
  • The state of the user.

    Returns UserState

    The state as an enumerated string.

Methods

  • Adds a listener that will be fired on various user related events. This includes auth token refresh, refresh token refresh, refresh custom user data, and logout.

    Parameters

    Returns void

  • Call a remote Atlas App Services Function by its name.

    Parameters

    • name: string

      Name of the App Services Function.

    • Rest ...args: unknown[]

      Arguments passed to the Function.

    Returns Promise<unknown>

    A promise that resolves to the value returned by the Function.

    Note

    Consider using functions[name]() instead of calling this method.

    Example

    // These are all equivalent:
    await user.callFunction("doThing", a1, a2, a3);
    await user.functions.doThing(a1, a2, a3);
    await user.functions["doThing"](a1, a2, a3);

    Example

    // The methods returned from the functions object are bound, which is why it's okay to store the function in a variable before calling it:
    const doThing = user.functions.doThing;
    await doThing(a1);
    await doThing(a2);
  • Link the user with an identity represented by another set of credentials.

    Parameters

    Returns Promise<void>

    A promise that resolves once the user has been linked with the credentials.

  • Log out the user.

    Returns Promise<void>

    A promise that resolves once the user has been logged out of the app.

  • Parameters

    • serviceName: string

      The name of the MongoDB service to connect to.

    Returns MongoDBService

    A client enabling access to a MongoDB service.

    Example

    let blueWidgets = user.mongoClient("myService")
    .db("myDb")
    .collection<Widget>("widgets")
    .find({ color: "blue" });
  • Refresh the access token and derive custom data from it.

    Returns Promise<UserCustomDataType>

    A promise that resolves to the refreshed custom data.

  • Removes all event listeners previously added via User.addListener.

    Returns void

  • Removes an event listener previously added via User.addListener.

    Parameters

    Returns void

Generated using TypeDoc