Spaces:
Running
Running
wip signin
Browse files- README.md +1 -0
- src/lib/components/sidebar/Sidebar.svelte +6 -3
- src/lib/stores/use-user.ts +9 -0
- src/routes/api/auth/login/+server.ts +10 -0
README.md
CHANGED
|
@@ -7,6 +7,7 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
app_port: 3000
|
| 9 |
license: mit
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 7 |
pinned: false
|
| 8 |
app_port: 3000
|
| 9 |
license: mit
|
| 10 |
+
hf_oauth: true
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
src/lib/components/sidebar/Sidebar.svelte
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
import cookies from 'js-cookie';
|
| 3 |
import Icon from "@iconify/svelte"
|
| 4 |
import { get } from 'svelte/store';
|
| 5 |
-
import { userStore } from "$lib/stores/use-user";
|
| 6 |
import { SIDEBAR_MENUS } from "$lib/utils";
|
| 7 |
import HFLogo from "$lib/assets/hf-logo.svg";
|
| 8 |
|
|
@@ -64,9 +64,12 @@
|
|
| 64 |
</button>
|
| 65 |
</footer>
|
| 66 |
{:else}
|
| 67 |
-
<
|
|
|
|
|
|
|
|
|
|
| 68 |
<img src={HFLogo} alt="Hugging Face logo" class="w-8 h-8 inline-block" />
|
| 69 |
<u>Sign in with Hugging Face</u>
|
| 70 |
-
</
|
| 71 |
{/if}
|
| 72 |
</aside>
|
|
|
|
| 2 |
import cookies from 'js-cookie';
|
| 3 |
import Icon from "@iconify/svelte"
|
| 4 |
import { get } from 'svelte/store';
|
| 5 |
+
import { userStore, openWindowLogin } from "$lib/stores/use-user";
|
| 6 |
import { SIDEBAR_MENUS } from "$lib/utils";
|
| 7 |
import HFLogo from "$lib/assets/hf-logo.svg";
|
| 8 |
|
|
|
|
| 64 |
</button>
|
| 65 |
</footer>
|
| 66 |
{:else}
|
| 67 |
+
<button
|
| 68 |
+
class="text-white text-center text-base pb-8 px-8 flex items-center justify-center gap-2 cursor-pointer"
|
| 69 |
+
on:click={openWindowLogin}
|
| 70 |
+
>
|
| 71 |
<img src={HFLogo} alt="Hugging Face logo" class="w-8 h-8 inline-block" />
|
| 72 |
<u>Sign in with Hugging Face</u>
|
| 73 |
+
</button>
|
| 74 |
{/if}
|
| 75 |
</aside>
|
src/lib/stores/use-user.ts
CHANGED
|
@@ -2,3 +2,12 @@ import { writable } from "svelte/store";
|
|
| 2 |
|
| 3 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 4 |
export const userStore = writable<any>(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 4 |
export const userStore = writable<any>(null);
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
export const openWindowLogin = async () => {
|
| 8 |
+
const response = await fetch(`/api/login`);
|
| 9 |
+
const { ok, redirect } = await response.json();
|
| 10 |
+
if (ok && redirect) {
|
| 11 |
+
window.open(redirect, "_blank");
|
| 12 |
+
}
|
| 13 |
+
};
|
src/routes/api/auth/login/+server.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { json } from '@sveltejs/kit';
|
| 2 |
+
/** @type {import('./$types').RequestHandler} */
|
| 3 |
+
|
| 4 |
+
export async function GET() {
|
| 5 |
+
const REDIRECT_URI = `https://${process.env.SPACE_HOST}/login/callback`
|
| 6 |
+
|
| 7 |
+
return json({
|
| 8 |
+
redirect: `https://huggingface.co/oauth/authorize?client_id=${process.env.OAUTH_CLIENT_ID}&redirect_uri=${REDIRECT_URI}&scope=openid%20profile&state=STATE&response_type=code`,
|
| 9 |
+
})
|
| 10 |
+
}
|