Class ScuteClient

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

appData: ScuteAppData
autoRefreshTicker: null | Timer = null
channel: null | BroadcastChannel = null
config: {
    autoRefreshToken: boolean;
    persistSession: undefined | boolean;
    refetchInverval: undefined | number;
    refetchOnWindowFocus: undefined | boolean;
}

Type declaration

  • autoRefreshToken: boolean
  • persistSession: undefined | boolean
  • refetchInverval: undefined | number
  • refetchOnWindowFocus: undefined | boolean
emitter: Emitter<InternalEvent>
getCurrentUserDeferred: null | Deferred<{
    data: {
        user: null;
    };
    error: BaseHttpError | InvalidAuthTokenError;
} | {
    data: {
        user: ScuteUserData;
    };
    error: null;
}> = null
initializeDeferred: null | Deferred<{
    error: null | ScuteError;
}> = null
instanceID: number = 0
logDebugMessages: boolean = false
refreshDeferred: null | Deferred<{
    data: null;
    error: BaseHttpError;
} | {
    data: Session;
    error: null;
}> = null
refreshProxyCallback: null | (() => Promise<void | Partial<ScuteTokenPayload>>) = null

Type declaration

scuteStorage: ScuteStorage | ScuteCookieStorage
visibilityChangedCallback: null | (() => Promise<any>) = null

Type declaration

    • (): Promise<any>
    • Returns Promise<any>

wretcher: Wretch<unknown, unknown, undefined>
nextInstanceID: number = 0

Methods

  • Internal

    Get access token from the current session.

    Parameters

    Returns Promise<{
        data: null;
        error: InvalidAuthTokenError;
    } | {
        data: {
            access: string;
        };
        error: null;
    }>

  • Internal
    • fresh needs to be set to true to get the latest data from the server.

    Parameters

    • Optional fresh: boolean

      Fetch new data from the server

    • emitRefetchEvent: boolean = true

      Emit refetch event when getting fresh data

    Returns Promise<{
        data: {
            session: Session;
            user: null;
        };
        error: InvalidAuthTokenError;
    } | {
        data: {
            session: Session;
            user: ScuteUserData;
        };
        error: null;
    } | {
        data: {
            session: null;
            user: null;
        };
        error: ScuteError;
    } | {
        data: {
            session: Session;
            user: null;
        };
        error: null;
    }>

  • Internal

    Initializes the client SDK (making sure it is initialized only once).

    Returns Promise<{
        error: null | ScuteError;
    }>

  • Internal

    Parameters

    • accessToken: string

      Auth token

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: {
            options: PublicKeyCredentialCreationOptionsJSON;
        };
        error: null;
    }>

  • Internal

    Parameters

    • identifier: string

      {ScuteIdentifier}

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: {
            options: undefined | PublicKeyCredentialRequestOptionsJSON;
        };
        error: null;
    }>

  • Parameters

    • userId: UniqueIdentifier

      {UniqueIdentifier}

    • options: undefined | PublicKeyCredentialRequestOptionsJSON

      Webauthn credential request options

    Returns Promise<boolean>

    true if the credential id is not found in the browser and server.

  • Clear remembered (last logged) identifier.

    Returns Promise<void>

  • Internal

    Emit an auth event so it can be listened to with onAuthStateChange.

    Parameters

    • event: AuthChangeEvent

      {AuthChangeEvent}

    • Optional session: null | Session

      {Session}

    • Optional user: null | ScuteUserData

      {ScuteUserData}

    Returns void

  • Get app config data. fresh needs to be set to true to get the latest data from the server.

    Parameters

    • fresh: boolean = false

      fetch new data from the server instead cached

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: ScuteAppData;
        error: null;
    }>

  • Get the access token from the current session.

    Returns Promise<{
        data: null;
        error: InvalidAuthTokenError;
    } | {
        data: {
            access: string;
        };
        error: null;
    }>

  • Get if the URL has magic link token.

    Parameters

    • Optional url: string | URL

      (Optional) magic link url with sct_magic param. Default window.location.href.

    Returns null | string

  • Get remembered (last logged) identifier.

    Returns Promise<null | string>

  • Get current session.

    Returns Promise<{
        data: {
            session: Session;
            user: null;
        };
        error: InvalidAuthTokenError;
    } | {
        data: {
            session: Session;
            user: ScuteUserData;
        };
        error: null;
    } | {
        data: {
            session: null;
            user: null;
        };
        error: ScuteError;
    } | {
        data: {
            session: Session;
            user: null;
        };
        error: null;
    }>

  • Check if any webauthn device registered on this device with the current user.

    Returns Promise<boolean>

    true if any webauthn credential is registered on this device with the current user, false otherwise.

  • Check if webauthn is supported on this device.

    Returns boolean

    true if webauthn is supported on this device, false otherwise.

  • Receive a notification every time an auth event happens.

    Parameters

    • callback: (<T>(event, session, user) => void)

      A callback function to be invoked when an auth event happens.

        • <T>(event, session, user): void
        • Type Parameters

          Parameters

          • event: AuthChangeEvent
          • session: T
          • user: T extends AuthenticatedSession
                ? ScuteUserData
                : null

          Returns void

    Returns (() => void)

      • (): void
      • Returns void

  • Refresh and save new auth token with current session.

    Returns Promise<{
        data: null;
        error: ScuteError;
    } | {
        data: Session;
        error: null;
    }>

  • Register refetch interval

    • (browser-only)

    Returns Promise<void>

  • Register callback for visibilitychange browser event.

    • (browser-only)

    Returns Promise<void>

  • Send login magic link and emit the pending event.

    Parameters

    • identifier: string

      {ScuteIdentifier}

    • Optional webauthnEnabled: boolean

      {boolean} - Magic link token includes this in the payload

    • emitEvent: boolean = true

      {boolean} - Emit pending event. Default true.

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: ScuteMagicLinkIdResponse;
        error: null;
    }>

  • Send register magic link and emit the pending event.

    Parameters

    • identifier: string

      {ScuteIdentifier}

    • Optional userMeta: Metadata
    • Optional webauthnEnabled: boolean

      {boolean}

    • emitEvent: boolean = true

      {boolean} - Emit pending event. Default true.

    Returns Promise<{
        data: ScuteMagicLinkIdResponse;
        error: null;
    } | {
        data: null;
        error: BaseHttpError;
    }>

  • Set refresh proxy callback. This is useful when you do not want to pass the refresh token to the client.

    Send request to your backend server to refresh session with secret key in callback function.

    • Needs backend server

    Parameters

    Returns Promise<void>

  • Internal

    Parameters

    • identifier: string

      {ScuteIdentifier}

    Returns Promise<void>

  • Log in an existing user with an email adress or phone number. Scute will try to sign in with webauthn if not disabled and supported by the browser, otherwise it will continue with fallback method.

    Parameters

    • identifier: string

      {ScuteIdentifier}

    • Optional options: ScuteSignInOptions

      {ScuteSignInOptions}

    Returns Promise<{
        data: ScuteMagicLinkIdResponse;
        error: null;
    } | {
        data: null;
        error: Error | WebAuthnError;
    } | {
        data: null;
        error: null;
    }>

    Polling data if webauthn is not available else null.

  • Log in with the magic link url.

    Parameters

    • Optional url: string | URL

      (Optional) magic link url with sct_magic param. Default window.location.href.

    Returns Promise<{
        error: UnknownSignInError;
    } | {
        error: null;
    }>

  • Verify the device (assert webauthn credentials) and log in.

    Parameters

    • identifier: string

      {ScuteIdentifier}

    Returns Promise<{
        error: null;
    } | {
        error: Error | WebAuthnError;
    }>

  • Log out a user by deleting their auth token in the storage and revoking their refresh token.

    Returns Promise<boolean>

    true if the refresh token is revoked successfully.

  • Start auto refresh interval in the background. The session is checked every few seconds.

    Returns Promise<void>

  • Stop auto refresh interval in the background (if any).

    Returns Promise<void>

  • Verify magic link token

    Parameters

    • token: string

      Magic link token (sct_magic)

    Returns Promise<{
        data: null;
        error: InvalidMagicLinkError;
    } | {
        data: {
            authPayload: ScuteTokenPayload;
            magicPayload: _ScuteMagicLinkTokenPayload;
        };
        error: null;
    }>

  • Finalizes webauthn login by attempting popup and sending credential to the server.

    Parameters

    • options: CredentialRequestOptionsJSON

      {webauthn.CredentialRequestOptionsJSON} - Credential request options

    Returns Promise<{
        data: null;
        error: Error | WebAuthnError;
    } | {
        data: ScuteTokenPayload;
        error: null;
    }>

  • Finalizes webauthn register by attempting popup and sending credential to the server.

    • Needs access token.

    Parameters

    • options: CredentialCreationOptionsJSON

      Credential creation options

    • accessToken: string

      Auth token

    Returns Promise<{
        data: null;
        error: Error | WebAuthnError;
    } | {
        data: ScuteUserSession;
        error: null;
    }>

  • Initialize webauthn login.

    Parameters

    • identifier: string

      {ScuteIdentifier}

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: {
            options: undefined | PublicKeyCredentialRequestOptionsJSON;
        };
        error: null;
    }>

  • Initializes webauthn register.

    • Needs access token.

    Parameters

    • accessToken: string

      Access token

    Returns Promise<{
        data: null;
        error: BaseHttpError;
    } | {
        data: {
            options: PublicKeyCredentialCreationOptionsJSON;
        };
        error: null;
    }>

Generated using TypeDoc