diff --git a/apps/web/package.json b/apps/web/package.json index 4361bd5..8dbdbde 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -30,6 +30,7 @@ }, "type": "module", "dependencies": { + "jwt-decode": "^3.1.2", "sugar": "^2.0.6", "tailwind-preset-base": "workspace:^", "ui": "workspace:^" diff --git a/apps/web/src/lib/components/layout/NavBar.svelte b/apps/web/src/lib/components/layout/NavBar.svelte index 0fd3428..7372028 100644 --- a/apps/web/src/lib/components/layout/NavBar.svelte +++ b/apps/web/src/lib/components/layout/NavBar.svelte @@ -1,11 +1,18 @@ -
@@ -19,8 +26,8 @@ {#if $isAuthenticated} - {user.username} - user icon + {$user.user.username} + user icon {:else} diff --git a/apps/web/src/lib/stores/user.ts b/apps/web/src/lib/stores/user.ts index bc71e09..985c0e6 100644 --- a/apps/web/src/lib/stores/user.ts +++ b/apps/web/src/lib/stores/user.ts @@ -1,4 +1,5 @@ import { writable } from "svelte/store"; export const isAuthenticated = writable(false); -export const user = writable(null); \ No newline at end of file +export const user = writable(null); +export const jwtKey = writable(null); \ No newline at end of file diff --git a/apps/web/src/routes/callback/github/+page.svelte b/apps/web/src/routes/callback/github/+page.svelte index f02f0f8..2207746 100644 --- a/apps/web/src/routes/callback/github/+page.svelte +++ b/apps/web/src/routes/callback/github/+page.svelte @@ -1,3 +1,18 @@ + + +
\ No newline at end of file diff --git a/apps/web/src/routes/callback/github/+page.ts b/apps/web/src/routes/callback/github/+page.ts index 8e682b7..2ab5b20 100644 --- a/apps/web/src/routes/callback/github/+page.ts +++ b/apps/web/src/routes/callback/github/+page.ts @@ -1,39 +1,26 @@ import { env } from '$env/dynamic/public'; import type { PageLoad } from './$types'; +import { redirect } from '@sveltejs/kit'; +import { jwtKey } from '$lib/stores/user'; export const load = (async ({ url: { searchParams }, fetch }) => { const code = searchParams.get('code'); if (!code) { - return { - status: 302, - headers: { - location: '/' - } - }; + throw redirect(302, '/'); } else { try { const response = await fetch(`${env.PUBLIC_API_URL}/auth/github?code=${code}`, { - method: 'POST' - }) - const { jwt } = await response.json(); - return { - status: 302, + method: 'POST', headers: { - location: '/', - 'set-cookie': `jwt=${jwt}; Path=/; HttpOnly` + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", } - }; + }) + const jwt = await response.json(); + jwtKey.set(jwt.jwt); } catch (error) { console.log(error) - return { - status: 500, - headers: { - location: '/' - }, - body: { - error: error.message - } - }; + throw redirect(302, '/'); } } }) satisfies PageLoad; \ No newline at end of file diff --git a/apps/web/src/routes/discover/+page.svelte b/apps/web/src/routes/discover/+page.svelte new file mode 100644 index 0000000..e69de29 diff --git a/apps/web/src/routes/mod/[mod]/+page.svelte b/apps/web/src/routes/mod/[mod]/+page.svelte index 43ac7fd..c748b6d 100644 --- a/apps/web/src/routes/mod/[mod]/+page.svelte +++ b/apps/web/src/routes/mod/[mod]/+page.svelte @@ -25,7 +25,7 @@ } -
+
=0.10.0'}