mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Refactor web to use OpenAPI SDK (#326)
* Refactor main index page * Refactor admin page * Refactor Auth endpoint * Refactor directory to prep for monorepo * Fixed refactoring path * Resolved file path in vite * Refactor photo index page * Refactor thumbnail * Fixed test * Refactor Video Viewer component * Refactor download file * Refactor navigation bar * Refactor upload file check * Simplify Upload Asset signature * PR feedback
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ExternalFetch, GetSession, Handle } from '@sveltejs/kit';
|
||||
import type { GetSession, Handle } from '@sveltejs/kit';
|
||||
import * as cookie from 'cookie';
|
||||
import { serverEndpoint } from '$lib/constants';
|
||||
import { session } from '$app/stores';
|
||||
import { api } from '@api';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
|
||||
@@ -13,14 +13,10 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
try {
|
||||
const { email, isAdmin, firstName, lastName, id, accessToken } = JSON.parse(cookies.session);
|
||||
|
||||
const res = await fetch(`${serverEndpoint}/auth/validateToken`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
});
|
||||
api.setAccessToken(accessToken);
|
||||
const { status } = await api.authenticationApi.validateAccessToken();
|
||||
|
||||
if (res.status === 201) {
|
||||
if (status === 201) {
|
||||
event.locals.user = {
|
||||
id,
|
||||
accessToken,
|
||||
@@ -35,7 +31,12 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.log('Error parsing session', error);
|
||||
if (error instanceof AxiosError) {
|
||||
console.log('Error validating token');
|
||||
return await resolve(event);
|
||||
}
|
||||
|
||||
console.log('Error parsing session');
|
||||
return await resolve(event);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user