diff --git a/src/client/lib/validateAccessToken.ts b/src/client/lib/validateAccessToken.ts index 8232ee6b..1e4f334d 100644 --- a/src/client/lib/validateAccessToken.ts +++ b/src/client/lib/validateAccessToken.ts @@ -1,6 +1,6 @@ import Cookies from "js-cookie"; -import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME, API_UID_COOKIE_NAME } from "../../lib/constants"; -import { client } from "src/trpc"; +import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME, API_UID_COOKIE_NAME } from "#lib/constants.js"; +import { client } from "../../trpc.js"; import moment from "moment"; diff --git a/src/components/Header.astro b/src/components/Header.astro index 13957a8b..b378595b 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -4,7 +4,7 @@ import ThemeController from "./ThemeController.svelte"; const valid = await validateAccessTokenServer(Astro) -const lightTheme = Astro.cookies.get("theme").value === "light"; +const lightTheme = Astro.cookies.get("theme")?.value === "light"; ---
diff --git a/src/lib/caller.ts b/src/lib/caller.ts index dd16f724..d4571d33 100644 --- a/src/lib/caller.ts +++ b/src/lib/caller.ts @@ -1,11 +1,11 @@ import { appRouter, t } from "@ibcornelsen/api"; -import { API_ACCESS_TOKEN_COOKIE_NAME } from "./constants"; +import { API_ACCESS_TOKEN_COOKIE_NAME } from "./constants.js"; export const createCaller = function (opts: any) { // 1. create a caller-function for your router const createCaller = t.createCallerFactory(appRouter); - const token = Buffer.from(opts.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME).value ?? "", "utf-8").toString("base64"); + const token = Buffer.from(opts.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value ?? "", "utf-8").toString("base64"); // 2. create a caller using your `Context` return createCaller({ authorization: `Bearer ${token}`, diff --git a/src/server/lib/validateAccessToken.ts b/src/server/lib/validateAccessToken.ts index 69946c6b..d284d478 100644 --- a/src/server/lib/validateAccessToken.ts +++ b/src/server/lib/validateAccessToken.ts @@ -1,12 +1,12 @@ -import { createCaller } from "#lib/caller"; -import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME, API_UID_COOKIE_NAME } from "#lib/constants"; +import { createCaller } from "#lib/caller.js"; +import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME, API_UID_COOKIE_NAME } from "#lib/constants.js"; import type { AstroGlobal } from "astro"; import moment from "moment"; export async function validateAccessTokenServer(astro: AstroGlobal) { - const accessToken = astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME).value; - const refreshToken = astro.cookies.get(API_REFRESH_TOKEN_COOKIE_NAME).value; + const accessToken = astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value; + const refreshToken = astro.cookies.get(API_REFRESH_TOKEN_COOKIE_NAME)?.value; if (!refreshToken) { // Wir haben keinen Refresh Token, also müssen wir uns neu anmelden.