fix(web): browser-side api client to include authorization token

This commit is contained in:
Connery Noble
2023-01-18 17:11:38 -08:00
parent 157d9b9cd7
commit 60e338938f
2 changed files with 27 additions and 1 deletions
+11
View File
@@ -1,6 +1,8 @@
<script lang="ts">
import '../app.css';
import { api } from '@api';
import * as cookieParser from 'cookie';
import { fade } from 'svelte/transition';
import { page } from '$app/stores';
import DownloadPanel from '$lib/components/asset-viewer/download-panel.svelte';
@@ -22,6 +24,7 @@
let showUploadCover = false;
onMount(async () => {
initApiAccessToken();
checkUserTheme();
const res = await checkAppVersion();
@@ -30,6 +33,14 @@
remoteVersion = res.remoteVersion ?? 'unknown';
});
const initApiAccessToken = () => {
const cookies = cookieParser.parse(document.cookie);
const accessToken = cookies['immich_access_token'];
if (accessToken) {
api.setAccessToken(accessToken);
}
};
const checkUserTheme = () => {
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
if (