Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
logic on signin
Browse files
src/routes/login/callback/+page.svelte
CHANGED
@@ -1,3 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="p-10">
|
2 |
<h1 class="text-white text-2xl font-bold">Login in progress..</h1>
|
3 |
</div>
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import { browser } from '$app/environment';
|
3 |
+
import cookies from 'js-cookie';
|
4 |
+
|
5 |
+
export let data;
|
6 |
+
|
7 |
+
if (data?.token) {
|
8 |
+
cookies.set('hf_access_token', data.token, { expires: 7 });
|
9 |
+
if (browser) {
|
10 |
+
window.location.href = '/';
|
11 |
+
}
|
12 |
+
}
|
13 |
+
</script>
|
14 |
+
|
15 |
<div class="p-10">
|
16 |
<h1 class="text-white text-2xl font-bold">Login in progress..</h1>
|
17 |
</div>
|
src/routes/login/callback/+page.ts
CHANGED
@@ -1,22 +1,19 @@
|
|
1 |
-
import cookies from "js-cookie";
|
2 |
-
import { redirect } from "@sveltejs/kit";
|
3 |
export async function load({ url, fetch }) {
|
4 |
const code = url.searchParams.get("code")
|
5 |
|
6 |
-
|
7 |
if (code) {
|
8 |
const request = await fetch(`/api/auth`, {
|
9 |
method: "POST",
|
10 |
body: JSON.stringify({ code }),
|
11 |
});
|
12 |
-
const { ok, token } = await request.json();
|
13 |
if (ok) {
|
14 |
-
|
15 |
-
throw redirect(302, "/")
|
16 |
}
|
17 |
}
|
18 |
|
19 |
return {
|
20 |
-
|
21 |
}
|
22 |
}
|
|
|
|
|
|
|
1 |
export async function load({ url, fetch }) {
|
2 |
const code = url.searchParams.get("code")
|
3 |
|
4 |
+
let token: string | undefined = undefined
|
5 |
if (code) {
|
6 |
const request = await fetch(`/api/auth`, {
|
7 |
method: "POST",
|
8 |
body: JSON.stringify({ code }),
|
9 |
});
|
10 |
+
const { ok, token: access_token } = await request.json();
|
11 |
if (ok) {
|
12 |
+
token = access_token;
|
|
|
13 |
}
|
14 |
}
|
15 |
|
16 |
return {
|
17 |
+
token
|
18 |
}
|
19 |
}
|