From d5229a2ab408d8338fb2c47719f17382fac25884 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 28 Aug 2023 07:28:20 +0200 Subject: [PATCH] Auth Token as Cookie --- src/authTokens.json | 4 +++ src/hooks.server.ts | 10 +++++- src/routes/Header.svelte | 31 +++++++++++++++- src/routes/Settings.svelte | 73 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/authTokens.json create mode 100644 src/routes/Settings.svelte diff --git a/src/authTokens.json b/src/authTokens.json new file mode 100644 index 0000000..60e857b --- /dev/null +++ b/src/authTokens.json @@ -0,0 +1,4 @@ +[ + "1234", + "5678" +] \ No newline at end of file diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 3d81f50..c18e2c2 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,7 +1,15 @@ import { redirect } from "@sveltejs/kit"; +import validAuthTokens from './authTokens.json'; export async function handle({ event, resolve }) { - event.locals.authenticated = true; + const cookie = event.cookies.get('authToken'); + if (typeof cookie !== 'undefined') { + event.locals.authenticated = validAuthTokens.includes(cookie); + } + else { + event.locals.authenticated = false; + } + if (event.url.pathname.startsWith('/admin')) { if (!event.locals.authenticated) { diff --git a/src/routes/Header.svelte b/src/routes/Header.svelte index a7a9a36..2be1cc5 100644 --- a/src/routes/Header.svelte +++ b/src/routes/Header.svelte @@ -1,8 +1,13 @@ + +
@@ -30,6 +35,9 @@
  • About
  • +
  • + +
  • Settings

    +
    + +
    + + + + {#if showAuthSaved} +

    Saved!

    + {/if} +
    +
    + Show Game Groups:
    + Group B
    + Ungrouped
    + +
    + +
    +
    +
    + + + + + \ No newline at end of file