|
@@ -4,10 +4,26 @@ import { env } from '$env/dynamic/public';
|
|
|
import { ImmichApi } from './api/api';
|
|
|
|
|
|
export const handle = (async ({ event, resolve }) => {
|
|
|
- event.locals.api = new ImmichApi({
|
|
|
- basePath: env.PUBLIC_IMMICH_SERVER_URL || 'http://immich-server:3001',
|
|
|
- accessToken: event.cookies.get('immich_access_token')
|
|
|
- });
|
|
|
+ const basePath = env.PUBLIC_IMMICH_SERVER_URL || 'http://immich-server:3001';
|
|
|
+ const accessToken = event.cookies.get('immich_access_token');
|
|
|
+ const api = new ImmichApi({ basePath, accessToken });
|
|
|
+
|
|
|
+ // API instance that should be used for all server-side requests.
|
|
|
+ event.locals.api = api;
|
|
|
+
|
|
|
+ if (accessToken) {
|
|
|
+ try {
|
|
|
+ const { data: user } = await api.userApi.getMyUserInfo();
|
|
|
+ event.locals.user = user;
|
|
|
+ } catch (err) {
|
|
|
+ const apiError = err as AxiosError;
|
|
|
+
|
|
|
+ // Ignore 401 unauthorized errors and log all others.
|
|
|
+ if (apiError.response?.status !== 401) {
|
|
|
+ console.error('[ERROR] hooks.server.ts [handle]:', err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const res = await resolve(event);
|
|
|
|