Skip to content

Instantly share code, notes, and snippets.

@EvanBurbidge
Created December 9, 2021 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanBurbidge/f08025b2702db86d02b6953f66edf83a to your computer and use it in GitHub Desktop.
Save EvanBurbidge/f08025b2702db86d02b6953f66edf83a to your computer and use it in GitHub Desktop.
Logout script expo client auth0
import React from 'react';
import jwtDecode from 'jwt-decode';
import * as AuthSession from 'expo-auth-session';
import { openAuthSessionAsync } from 'expo-web-browser';
import { Alert, Button, Platform, StyleSheet, Text, View } from 'react-native';
const auth0ClientId = "";
const authorizationEndpoint = "https://youraccount.eu.auth0.com/v2/logout";
const useProxy = Platform.select({ web: false, default: true });
const redirectUri = AuthSession.makeRedirectUri({ useProxy }); // <-- must be set in allowed logout urls
export default function Logout() {
const logout = async () => {
try {
await openAuthSessionAsync(`${authorizationEndpoint}?client_id=${auth0ClientId}&returnTo=${redirectUri}`, 'redirectUrl');
// handle unsetting your user from store / context / memory
} catch (err) {
console.error(err)
}
}
return (
<View style={styles.container}>
<Button
title="Logout"
onPress={logout}
/>
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment