-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { LayoutServerLoad } from "./$types"; | ||
|
||
export const load = (({ locals }) => { | ||
return { | ||
authenticated: locals.user !== null | ||
} | ||
}) satisfies LayoutServerLoad; |
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,5 +1,23 @@ | ||
<script lang="ts"> | ||
import LoginGoogleButton from '$lib/components/auth/LoginGoogleButton.svelte'; | ||
</script> | ||
import { browser } from '$app/environment'; | ||
import { goto } from '$app/navigation'; | ||
import { onMount } from 'svelte'; | ||
import { z } from 'zod'; | ||
onMount(async () => { | ||
if (browser) { | ||
const response = await fetch('/auth?/loginGoogle', { method: 'POST', body: '' }); | ||
const redirect = z | ||
.object({ | ||
status: z.number(), | ||
location: z.string() | ||
}) | ||
.parse(await response.json()); | ||
<LoginGoogleButton /> | ||
// if code is 302, redirect to the google login page | ||
if (redirect.status === 302) { | ||
window.location.href = redirect.location; | ||
} | ||
} | ||
}); | ||
</script> |