Back

Trying to add a Log out/Sign out button

  • 1
  • React Native
  • Auth
  • General
Samneh 2
28 Sep, 2024, 15:23

Trying to add a sign out button, using Expo, trying to end the session but after MANY attempts, i am unable to do so, export const returnSessions = async () => { return account.listSessions(); } export async function signOut() { try { // Delete all sessions for the currently authenticated user await account.deleteSessions(); console.log('All user sessions deleted successfully.'); } catch (error) { console.error('Error deleting sessions:', error.message); } }

TypeScript
const logout = async () => {
    setIsLoading(true); // Show a loading state
    try {
        await signOut(); // Attempt to sign out
        setUser(null); // Clear the user state
        setIsLogged(false); // Update the logged state
        router.replace("../sign-in"); // Redirect to sign-in page
    } catch (error) {
        console.error('Logout failed:', error.message); // Log the error message
    } finally {
        setIsLoading(false); // Hide the loading state regardless of success or failure
    }
};

this is what i have so far. can someone please help 😢

TL;DR
Developers are trying to add a sign out button using Expo but are having trouble ending the session even after several attempts. The provided code includes functions to list sessions and sign out, but the sign out process is not working as expected. The desired outcome is to clear the user state, update the logged state, and redirect to the sign-in page upon logout.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more