Guide
Logout

Finally, we can add a log out function for the user. This will revoke the access token and sign out from the Google account as well as from Okto. The user will be redirected to the login screen after the logout.

Add logout function

Lets start by adding a function that can handle the logout. This function will sign out the user from the Google account and we can use the logout method from Okto to expire the access token and refresh token and end the session from Okto Wallet as well.

screen/user-profile.tsx
import { useOkto } from 'okto-sdk-react-native';
import { GoogleSignin } from "@react-native-google-signin/google-signin";
 
...
 
const UserProfileScreen = () => {
    const { logout } = useOkto();
    ...
 
    const handleLogout = async () => {
        try {
            await GoogleSignin.revokeAccess();
            await GoogleSignin.signOut();
            await logout();
        } catch (error) {
            console.error(error);
        }
    };
};

Add logout button

Now we can add a logout button at the top of the user profile screen to trigger the logout function.

screen/user-profile.tsx
import { View, Button } from 'react-native';
 
const UserProfileScreen = () => {
    ...
 
    return (
        <View style={{ flex: 1, backgroundColor: '#fff' }}>
            <View style={{ flexDirection: "row", justifyContent: "flex-end", marginTop: 10 }}>
                <Button
                    title="Logout"
                    onPress={handleLogout}
                    color="red"
                />
            </View>
 
            ...
 
        </View>
    )
}