Managing sessions and tokens in React Native
PingOne React Native
After a DaVinci flow completes successfully, you can inspect the user’s active session and manage the OIDC tokens it contains.
The React Native DaVinci module does not expose a separate server session token alongside the OIDC access and refresh tokens.
The examples on this page use the client directly. You can call the same methods through the actions returned by useDaVinci.
The user(), refresh(), and userinfo() methods return null only when there is no active session.
If retrieving the session or the user information fails, the operation rejects with a DaVinciError whose code property is DAVINCI_SESSION_ERROR.
For more information about handling errors, see Error handling.
Getting session information
After the flow reaches SuccessNode, call user() to retrieve the active OIDC session:
const session = await davinciClient.user();
console.log('Access token:', session?.accessToken);
console.log('Refresh token:', session?.refreshToken);
console.log('Expires in:', session?.expiresIn);
user() returns null if there is no active session.
The returned session includes the following properties when they are available:
accessToken-
The OAuth 2.0 access token.
refreshToken-
The OAuth 2.0 refresh token, if issued.
expiresIn-
The access token lifetime in seconds, if provided.
Refreshing tokens
Call refresh() to obtain an updated session using the current refresh token:
const refreshedSession = await davinciClient.refresh();
console.log('New access token:', refreshedSession?.accessToken);
The method returns the updated session or null if no active session is available.
Getting user information
Call userinfo() to retrieve the user’s claims from the OIDC user information endpoint:
Fetching user information
const userInfo = await davinciClient.userinfo();
console.log(userInfo);
The method returns the claims as an object, or null if there is no active session.
Revoking tokens
To request revocation of the active access and refresh tokens, call revoke():
const revoked = await davinciClient.revoke();
console.log('Tokens revoked:', revoked);
The revoke() call returns a Boolean result from the native DaVinci module.
Use logoutUser() to completely sign out an authenticated user and clear the active DaVinci session.