1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 05:46:46 +01:00
immich/web/src/hooks.ts
Alex 83cbf51704
Use cookies for client requests (#377)
* Use cookie for frontend request

* Remove api helper to use SDK

* Added error handling to status box

* Remove additional places that check for session.user

* Refactor sending password

* prettier clean up

* remove deadcode

* Move all authentication requests to the client

* refactor upload panel to only fetch assets after the upload panel disappear

* Added keydown to remove focus on title change on album viewer
2022-07-26 12:28:07 -05:00

31 lines
780 B
TypeScript

import type { ExternalFetch, GetSession, Handle } from '@sveltejs/kit';
import * as cookie from 'cookie';
import { api } from '@api';
export const handle: Handle = async ({ event, resolve }) => {
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
if (!cookies['immich_is_authenticated']) {
return await resolve(event);
}
const accessToken = cookies['immich_access_token'];
try {
api.setAccessToken(accessToken);
const { data } = await api.userApi.getMyUserInfo();
event.locals.user = data;
return await resolve(event);
} catch (error) {
event.locals.user = undefined;
return await resolve(event);
}
};
export const getSession: GetSession = async ({ locals }) => {
if (!locals.user) return {};
return {
user: locals.user
};
};