I’ve been using this approach until recently when I added a sign out button inside of a Drawer navigator’s menu and the app was crashing after the sign out flow finished.
My apps are using Keycloak for authentication and the fix was to also provide id_token_hint
(which is literally the ID token of the user) through query params so it does not get the user to a page where they need to press a button to logout. Now I just make the request with axios and it works properly.
Sample code:
export const logout = async (idToken?: string) => {
const discovery = await getDiscoveryAsync();
const params: Record<string, string> = {
client_id: CLIENT_ID,
};
if (idToken) params.id_token_hint = idToken;
const paramsStr = Object.entries(params)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join("&");
const response = await axios.get(
`${discovery.endSessionEndpoint}?${paramsStr}`
);
if (response.status !== 200) return false;
return true;
};