I'm trying to wrap my head around authentication with Auth0 in a React Native Expo app, however I don't seem to be able to log out. This means I'm not able to switch login accounts either. I'm able to log in the first time I start the app on a new device. After the initial login, silent auth kicks in, and since I'm not able to sign out, I stay signed in.
On logout, I'm hitting Auth0 logout url:
const logout = async () => {
try {
await axios.get(`${domainUrl}/v2/logout?client_id=${clientId}`)
} catch (err) {
console.error(err)
}
}
....
<Button
title='Sign out'
onPress={logout}
/>
In my Auth0 logs, Auth0 clearly states that: User successfully logged out
I'm using the AuthSessionNew.useAuthRequest() to handle the login:
const [request, response, promptAsync] = AuthSessionNew.useAuthRequest(
{
clientId,
responseType: 'id_token',
scopes: ['app', 'name'],
extraParams: {
nonce: 'nonce',
},
redirectUri,
},
discovery,
)
....
<Button
disabled={!request}
title='Sign in'
onPress={() => promptAsync({ useProxy })}
/>
As with the logout, I get a successful login in the Auth0 logs whenever I invoke my login-button: Successful login
The response starts out as null, until the first login. After login, it persists even if the app gets closed or not. I suppose this is a wanted behavior, as you can see if the user is signed in to the application or not this way. However, I guess it should be cleared out once I make the call to the logout route.
Does anyone have any idea what's going on here? Why am I not able to log out, even though the Auth0 logs says otherwise?
Documentation at https://auth0.com/docs/api/authentication?http#logout
As this is a mobile app, I don't have a redirect-url after logout.
I've also tried the federated and it makes no difference.
The response object looks like this:
Object {
"authentication": null,
"error": null,
"errorCode": null,
"params": Object {
"exp://192.168.10.187:19000/--/expo-auth-session": "",
"id_token": "JWT-TOKEN",
"state": "BQK8UJc9sK",
},
"type": "success",
"url": "exp://192.168.10.187:19000/--/expo-auth-session#id_token=JWT-TOKEN",
}
Not sure why it says authentication: null and type: success
I would really appreciate som fresh eyes looking at this. If anything information is missing, just tell me and I'll add it to the post. Thanks in advance.
Stephan Valois