2024-08-14 03:49:23 +10:00
|
|
|
import api from 'mastodon/api';
|
2019-08-27 02:24:10 +10:00
|
|
|
|
2024-08-14 03:49:23 +10:00
|
|
|
export async function logOut() {
|
|
|
|
try {
|
|
|
|
const response = await api(false).delete<{ redirect_to?: string }>(
|
|
|
|
'/auth/sign_out',
|
|
|
|
{ headers: { Accept: 'application/json' }, withCredentials: true },
|
|
|
|
);
|
2019-08-27 02:24:10 +10:00
|
|
|
|
2024-08-14 03:49:23 +10:00
|
|
|
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);
|
2019-08-27 02:24:10 +10:00
|
|
|
}
|
2024-08-14 03:49:23 +10:00
|
|
|
}
|