Skip to main content
Version: 0.15.X

Using Session

Session recipe is integrated with the EmailPassword recipe. That means that when a user signs in, it automatically creates a secure session for that user.

The Session module is essentially a wrapper around the supertokens-website session management package.

If you were using this package and would like to upgrade to use supertokens-auth-react, please contact us at [email protected]

Reference guide#

doesSessionExist#

  • Description:#

    Use doesSessionExist when you want to know if a user is logged in or not.

  • Output:#

    Promise<bool>

  • Example:#

        import {doesSessionExist} from 'supertokens-auth-react/recipe/session';
        const isLoggedIn = await doesSessionExist();

getUserId#

  • Description:#

    Return user id

  • Output:#

    Promise<string>

  • Example:#

        import {getUserId} from 'supertokens-auth-react/recipe/session';
        const userId = await getUserId();

getRefreshURLDomain#

  • Description:#

    Return refresh URL Domain

  • Output:#

    string

  • Example:#

        import {getRefreshURLDomain} from 'supertokens-auth-react/recipe/session';
        const refreshUrlDomain = getRefreshURLDomain();

getJWTPayloadSecurely#

  • Description:#

    Return user JWT Payload

  • Output:#

    Promise<any>

  • Example:#

        import {getJWTPayloadSecurely} from 'supertokens-auth-react/recipe/session';
        const userJWTPayload = await getJWTPayloadSecurely();

attemptRefreshingSession#

  • Description:#

    Attempt to refresh session

  • Output:#

    Promise<any>

  • Example:#

        import {attemptRefreshingSession} from 'supertokens-auth-react/recipe/session';
        const hasRefreshedSession = await attemptRefreshingSession();

addAxiosInterceptors#

  • Description:#

    Return user JWT Payload. Call this function once when your application starts if you are using axios to communicate with your API.

  • Example:#

        import {addAxiosInterceptors} from 'supertokens-auth-react/recipe/session';    import axios from "axios";
        addAxiosInterceptors(axios);