Skip to content

Commit f6ef54f

Browse files
Switch login endpoints to +page.server, fix logout refresh
1 parent 7839a6d commit f6ef54f

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
toast.success("Logged out", {
251251
description: "You have been logged out. Refreshing in 3 seconds...",
252252
duration: 3000,
253-
onAutoClose: location.reload
253+
onAutoClose: () => location.reload()
254254
});
255255
}}
256256
class="cursor-pointer text-red-500"

src/routes/login/+server.ts renamed to src/routes/login/+page.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { redirect } from "@sveltejs/kit";
22
import { generateState } from "arctic";
33
import { github } from "$lib/server/auth";
44

5-
export async function GET({ cookies }) {
5+
export async function load({ cookies }) {
66
const state = generateState();
77
const url = await github.createAuthorizationURL(state);
88

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1+
import { error, redirect } from "@sveltejs/kit";
12
import { github } from "$lib/server/auth";
23
import { tokenKey } from "$lib/types";
34

4-
export async function GET({ cookies, url }) {
5+
export async function load({ cookies, url }) {
56
const code = url.searchParams.get("code");
67
const state = url.searchParams.get("state");
78
const storedState = cookies.get("github_oauth_state") ?? null;
89

910
if (!code || !state || !storedState || state !== storedState) {
10-
return new Response(null, {
11-
status: 400
12-
});
11+
error(400);
1312
}
1413
cookies.delete("github_oauth_state", {
1514
path: "/"
1615
});
1716

1817
const tokens = await github.validateAuthorizationCode(code);
1918

20-
return new Response(null, {
21-
status: 302,
22-
headers: {
23-
Location: `/?${tokenKey}=${tokens.accessToken}`
24-
}
25-
});
19+
return redirect(302, `/?${tokenKey}=${tokens.accessToken}`);
2620
}

0 commit comments

Comments
 (0)