catstodon/app/javascript/flavours/glitch/utils/log_out.ts
Renaud Chaput 09929a42f7 [Glitch] Fix log out from user menu not working on Safari
Port c3e1d86d58 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2024-08-14 21:24:50 +02:00

20 lines
616 B
TypeScript

import api from 'flavours/glitch/api';
export async function logOut() {
try {
const response = await api(false).delete<{ redirect_to?: string }>(
'/auth/sign_out',
{ headers: { Accept: 'application/json' }, withCredentials: true },
);
if (response.status === 200 && response.data.redirect_to)
window.location.href = response.data.redirect_to;
else
console.error(
'Failed to log out, got an unexpected non-redirect response from the server',
response,
);
} catch (error) {
console.error('Failed to log out, response was an error', error);
}
}