-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
48 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export const isAuthenticated = writable(false); | ||
export const user = writable(null); | ||
export const user = writable(null); | ||
export const jwtKey = writable(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { goto } from '$app/navigation'; | ||
import { isAuthenticated, user, jwtKey } from '$lib/stores/user'; | ||
import jwt_decode from 'jwt-decode'; | ||
onMount(() => { | ||
document.cookie = `auth=${$jwtKey}; path=/; expires=${new Date(Date.now() + 1000 * 60 * 60 * 24).toUTCString()}`; | ||
$isAuthenticated = true; | ||
$user = jwt_decode($jwtKey); | ||
goto('/') | ||
}) | ||
</script> | ||
|
||
|
||
<div class="h-screen"> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.