mirror of
https://github.com/immich-app/immich.git
synced 2025-12-19 01:11:07 +03:00
refactor: move managers to new folder (#17929)
This commit is contained in:
33
web/src/lib/managers/auth-manager.svelte.ts
Normal file
33
web/src/lib/managers/auth-manager.svelte.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user