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:
bool
Example:
import {doesSessionExist} from 'supertokens-auth-react/recipe/session'; const isLoggedIn = doesSessionExist();
getUserId
Description:
Return user id
Output:
string
Example:
import {getUserId} from 'supertokens-auth-react/recipe/session'; const userId = 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);
setAuth0API
Description:
Attempt to refresh session
Input:
apiPath: string
Example:
import {setAuth0API} from 'supertokens-auth-react/recipe/session'; setAuth0API("AUTH0_API_PATH"); // Replace with your value.
getAuth0API
Description:
Return Auth0 API Path
Output:
string
Example:
import {getAuth0API} from 'supertokens-auth-react/recipe/session'; const auth0APIPath = getAuth0API();