mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
34 lines
787 B
TypeScript
34 lines
787 B
TypeScript
import { goto } from '$app/navigation';
|
|
import { AppRoute } from '$lib/constants';
|
|
import { eventManager } from '$lib/managers/event.manager.svelte';
|
|
import { logout } from '@immich/sdk';
|
|
|
|
class AuthManager {
|
|
async logout() {
|
|
let redirectUri;
|
|
|
|
try {
|
|
const response = await logout();
|
|
if (response.redirectUri) {
|
|
redirectUri = response.redirectUri;
|
|
}
|
|
} catch (error) {
|
|
console.log('Error logging out:', error);
|
|
}
|
|
|
|
redirectUri = redirectUri ?? AppRoute.AUTH_LOGIN;
|
|
|
|
try {
|
|
if (redirectUri.startsWith('/')) {
|
|
await goto(redirectUri);
|
|
} else {
|
|
globalThis.location.href = redirectUri;
|
|
}
|
|
} finally {
|
|
eventManager.emit('auth.logout');
|
|
}
|
|
}
|
|
}
|
|
|
|
export const authManager = new AuthManager();
|