Session Management
Logout
Learn how to handle logout using sessionClear() method.
The sessionClear()
method ensures Okto-specific session data is removed from local storage, effectively revoking the session for that user on the client side.
Note
When using Google as the third-party provider, make sure to call googleLogout()
to reset any values Google may have stored in the client's local storage or cookies. The sessionClear()
method ensures Okto-specific session data is removed from local storage, effectively revoking the session for that user on the client side.
Example
import { useOkto } from '@okto_web3/react-native-sdk';
import { googleLogout } from "@react-oauth/google";
import { View, Text, Pressable } from 'react-native';
function LogoutComponent() {
const oktoClient = useOkto();
async function handleLogout() {
try {
googleLogout(); // Perform Google OAuth logout and remove stored token
oktoClient.sessionClear();
localStorage.removeItem("googleIdToken");
navigate("/");
return { result: "Logout success" };
} catch (error) {
console.error("Logout failed:", error);
return { result: "Logout failed" };
}
}
return (
<View>
<Pressable onPress={handleLogout}>
<Text>Login with Google</Text>
</Pressable>
</View>
);
}
Best Practice
To ensure users are fully logged out:
- Always clear both Okto and OAuth provider sessions.
- Remove any custom tokens from local storage (e.g.,
googleIdToken
).
Note
For error handling:
- Use the error code to debug issues. Check out the SDK errors and warnings documentation
- For help, navigate to the troubleshooting guide to contact support
Method Overview
Method | Description |
---|---|
async OktoClient.sessionClear() | Clears the current user session. |