aboutsummaryrefslogtreecommitdiffstats
path: root/apps/kit
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-10-01 17:23:12 +0200
committerivarlovlie <git@ivarlovlie.no>2022-10-01 17:23:12 +0200
commit0d368c5ce0b3a370d66e887e94497c28d5e91f7f (patch)
tree60fce619851079ec10de7ed7a6e2b0ffade3b6e2 /apps/kit
parent797596e1a389d255cc72e7351e84e89478dc161c (diff)
downloadgreatoffice-0d368c5ce0b3a370d66e887e94497c28d5e91f7f.tar.xz
greatoffice-0d368c5ce0b3a370d66e887e94497c28d5e91f7f.zip
feat: Revert to using built-in fetch since we are not required to use https after all
Not needing https is due to the change of api url in dev from 127.0.0.1 to localhost. Which previously gave us an incompatible cookie that would not be set on clients, since it came from an unsecure context (non-https api).
Diffstat (limited to 'apps/kit')
-rw-r--r--apps/kit/src/routes/(main)/+layout.server.ts37
1 files changed, 11 insertions, 26 deletions
diff --git a/apps/kit/src/routes/(main)/+layout.server.ts b/apps/kit/src/routes/(main)/+layout.server.ts
index ba0cd41..6bc7071 100644
--- a/apps/kit/src/routes/(main)/+layout.server.ts
+++ b/apps/kit/src/routes/(main)/+layout.server.ts
@@ -1,35 +1,20 @@
-import { api_base, CookieNames, is_development } from "$lib/configuration";
+import { api_base, CookieNames } from "$lib/configuration";
import { logError } from "$lib/logger";
import { error, redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";
-import { request, Agent, Pool } from "undici";
export const load: LayoutServerLoad = async ({ routeId, cookies }) => {
const isPublicRoute = routeId?.startsWith("(main)/(public)") ?? true;
- const sessionCookie = cookies.get(CookieNames.session);
- let sessionIsValid = false;
- if (is_development()) {
- sessionIsValid = (await request(api_base("_/valid-session"), {
- throwOnError: false,
- dispatcher: new Agent({
- factory: (origin, opts) => {
- return new Pool(origin, opts);
- }
- })
- })).statusCode === 200;
- } else {
- sessionIsValid = (await fetch(api_base("_/valid-session"), {
- headers: {
- Cookie: CookieNames.session + "=" + sessionCookie,
- }
- }).catch((e) => {
- logError(e);
- throw error(503, {
- message: "We are experiencing a service distruption! Have patience while we resolve the issue."
- })
- })).ok;
- }
-
+ let sessionIsValid = (await fetch(api_base("_/valid-session"), {
+ headers: {
+ Cookie: CookieNames.session + "=" + cookies.get(CookieNames.session)
+ }
+ }).catch((e) => {
+ logError(e);
+ throw error(503, {
+ message: "We are experiencing a service distruption! Have patience while we resolve the issue."
+ })
+ })).ok;
if (sessionIsValid && isPublicRoute) {
throw redirect(302, "/home");
} else if (!sessionIsValid && !isPublicRoute) {