Ditto JS SDK v5.0.0
    Preparing search index...

    Class Authenticator

    Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using a server connection mode.

    Index

    Properties

    loginSupported: boolean

    Returns true if authentication is available and the login methods can be used, otherwise returns false. Currently, authentication is only available if Ditto was initialized with an "server" connection mode (i.e. DittoConfigConnectServer).

    Accessors

    • get DEVELOPMENT_PROVIDER(): string

      The built-in development authentication provider to be used together with development authentication tokens.

      Returns string

      Authenticator.login() for more information about the provider parameter.

    Methods

    • Log in to Ditto with a third-party token.

      Returns a promise that resolves to a LoginResult object. When the login attempt is successful, the error property of the response will be null, otherwise it will contain a DittoError object with details about the error.

      If the authentication service provides additional client info, it will be returned in the clientInfo property of the response, whether the login attempt was successful or not.

      Parameters

      • token: string

        The authentication token required to log in.

      • provider: string

        The name of the authentication provider. Use Authenticator.DEVELOPMENT_PROVIDER with development tokens.

      Returns Promise<LoginResult>

      A promise that resolves to a LoginResult object.

      DittoError authentication/failed-to-authenticate if the Ditto instance is closed.

    • Log out of Ditto.

      This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. Note that this does not remove any data from the store. If you wish to delete data from the store then use the optional cleanupFn parameter to perform any required cleanup.

      Parameters

      • OptionalcleanupFn: (ditto: Ditto) => void

        An optional function that will be called with the relevant [Ditto] instance as the sole argument that allows you to perform any required cleanup of the store as part of the logout process.

      Returns Promise<void>

    • Sets the handler that will be called when authentication for this Ditto instance is about to expire.

      Assign a handler function to be notified before authentication expires, allowing you to login or perform other necessary actions.

      Returns Promise<void>