Interface Auth0ContextInterface<TUser>

Contains the authenticated state and authentication methods provided by the useAuth0 hook.

interface Auth0ContextInterface {
    error?: Error;
    getAccessTokenSilently: {
        (options): Promise<GetTokenSilentlyVerboseResponse>;
        (options?): Promise<string>;
        (options): Promise<string | GetTokenSilentlyVerboseResponse>;
    };
    getAccessTokenWithPopup: ((options?, config?) => Promise<undefined | string>);
    getIdTokenClaims: (() => Promise<undefined | IdToken>);
    handleRedirectCallback: ((url?) => Promise<RedirectLoginResult<any>>);
    isAuthenticated: boolean;
    isLoading: boolean;
    loginWithPopup: ((options?, config?) => Promise<void>);
    loginWithRedirect: ((options?) => Promise<void>);
    logout: ((options?) => Promise<void>);
    user?: TUser;
}

Type Parameters

Hierarchy

  • AuthState<TUser>
    • Auth0ContextInterface

Properties

error?: Error
getAccessTokenSilently: {
    (options): Promise<GetTokenSilentlyVerboseResponse>;
    (options?): Promise<string>;
    (options): Promise<string | GetTokenSilentlyVerboseResponse>;
}

Type declaration

    • (options): Promise<GetTokenSilentlyVerboseResponse>
    • const token = await getAccessTokenSilently(options);
      

      If there's a valid token stored, return it. Otherwise, opens an iframe with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

      If refresh tokens are used, the token endpoint is called directly with the 'refresh_token' grant. If no refresh token is available to make this call, the SDK falls back to using an iframe to the '/authorize' URL.

      This method may use a web worker to perform the token call if the in-memory cache is used.

      If an audience value is given to this function, the SDK always falls back to using an iframe to make the token exchange.

      Note that in all cases, falling back to an iframe requires access to the auth0 cookie.

      Parameters

      Returns Promise<GetTokenSilentlyVerboseResponse>

    • (options?): Promise<string>
    • const token = await getAccessTokenSilently(options);
      

      If there's a valid token stored, return it. Otherwise, opens an iframe with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

      If refresh tokens are used, the token endpoint is called directly with the 'refresh_token' grant. If no refresh token is available to make this call, the SDK falls back to using an iframe to the '/authorize' URL.

      This method may use a web worker to perform the token call if the in-memory cache is used.

      If an audience value is given to this function, the SDK always falls back to using an iframe to make the token exchange.

      Note that in all cases, falling back to an iframe requires access to the auth0 cookie.

      Parameters

      Returns Promise<string>

    • (options): Promise<string | GetTokenSilentlyVerboseResponse>
    • const token = await getAccessTokenSilently(options);
      

      If there's a valid token stored, return it. Otherwise, opens an iframe with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

      If refresh tokens are used, the token endpoint is called directly with the 'refresh_token' grant. If no refresh token is available to make this call, the SDK falls back to using an iframe to the '/authorize' URL.

      This method may use a web worker to perform the token call if the in-memory cache is used.

      If an audience value is given to this function, the SDK always falls back to using an iframe to make the token exchange.

      Note that in all cases, falling back to an iframe requires access to the auth0 cookie.

      Parameters

      Returns Promise<string | GetTokenSilentlyVerboseResponse>

getAccessTokenWithPopup: ((options?, config?) => Promise<undefined | string>)

Type declaration

    • (options?, config?): Promise<undefined | string>
    • const token = await getTokenWithPopup(options, config);
      

      Get an access token interactively.

      Opens a popup with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

      Parameters

      Returns Promise<undefined | string>

getIdTokenClaims: (() => Promise<undefined | IdToken>)

Type declaration

    • (): Promise<undefined | IdToken>
    • const claims = await getIdTokenClaims();
      

      Returns all claims from the id_token if available.

      Returns Promise<undefined | IdToken>

handleRedirectCallback: ((url?) => Promise<RedirectLoginResult<any>>)

Type declaration

    • (url?): Promise<RedirectLoginResult<any>>
    • After the browser redirects back to the callback page, call handleRedirectCallback to handle success and error responses from Auth0. If the response is successful, results will be valid according to their expiration times.

      Parameters

      • Optional url: string

        The URL to that should be used to retrieve the state and code values. Defaults to window.location.href if not given.

      Returns Promise<RedirectLoginResult<any>>

isAuthenticated: boolean
isLoading: boolean
loginWithPopup: ((options?, config?) => Promise<void>)

Type declaration

    • (options?, config?): Promise<void>
    • await loginWithPopup(options, config);
      

      Opens a popup with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

      IMPORTANT: This method has to be called from an event handler that was started by the user like a button click, for example, otherwise the popup will be blocked in most browsers.

      Parameters

      Returns Promise<void>

loginWithRedirect: ((options?) => Promise<void>)

Type declaration

    • (options?): Promise<void>
    • await loginWithRedirect(options);
      

      Performs a redirect to /authorize using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated.

      Parameters

      Returns Promise<void>

logout: ((options?) => Promise<void>)

Type declaration

    • (options?): Promise<void>
    • auth0.logout({ logoutParams: { returnTo: window.location.origin } });
      

      Clears the application session and performs a redirect to /v2/logout, using the parameters provided as arguments, to clear the Auth0 session. If the logoutParams.federated option is specified, it also clears the Identity Provider session. Read more about how Logout works at Auth0.

      Parameters

      Returns Promise<void>

user?: TUser