enzostvs HF staff commited on
Commit
22d2310
β€’
1 Parent(s): bb7c361

wip signin

Browse files
src/lib/components/sidebar/Sidebar.svelte CHANGED
@@ -24,11 +24,6 @@
24
  cookies.remove("hf_access_token");
25
  window.location.href = "/";
26
  }
27
- // if (!e.data.code) return;
28
- // if (e.data.type === "user-oauth" && e?.data?.code && !events.code) {
29
- // events.code = e.data.code;
30
- // loginFromCode(e.data.code);
31
- // }
32
  </script>
33
 
34
  <button class="bg-transparent absolute top-10 right-8 cursor-pointer xl:hidden" on:click="{handleClick}">
 
24
  cookies.remove("hf_access_token");
25
  window.location.href = "/";
26
  }
 
 
 
 
 
27
  </script>
28
 
29
  <button class="bg-transparent absolute top-10 right-8 cursor-pointer xl:hidden" on:click="{handleClick}">
src/lib/stores/use-user.ts CHANGED
@@ -1,32 +1,21 @@
1
  import { writable } from "svelte/store";
2
- import cookies from "js-cookie";
3
- import { env } from "$env/dynamic/public";
4
 
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
  export const userStore = writable<any>(null);
7
 
8
  export const openWindowLogin = async () => {
9
- console.log(window)
10
- if (window.location.host.includes("huggingface.co")) {
11
- console.log("redirecting to public space", env.PUBLIC_SPACE_URL)
12
- window.location.href = env.PUBLIC_SPACE_URL as string;
13
- return
14
- }
15
- return window.open(
16
- "/api/auth/login",
17
- "Login to LoRAs Studio",
18
- "menubar=no,width=500,height=777,location=no,resizable=no,scrollbars=yes,status=no"
19
- );
20
  };
21
 
22
- export const loginFromCode = async (code: string) => {
23
- const request = await fetch(`/api/auth`, {
24
- method: "POST",
25
- body: JSON.stringify({ code }),
26
- });
27
- const { ok, token } = await request.json();
28
- if (ok) {
29
- cookies.set("hf_access_token", token, { expires: 1, domain: process.env.SPACE_HOST });
30
- window.location.reload();
31
- }
32
- };
 
1
  import { writable } from "svelte/store";
2
+ // import cookies from "js-cookie";
 
3
 
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
  export const userStore = writable<any>(null);
6
 
7
  export const openWindowLogin = async () => {
8
+ window.location.href = "/api/auth/login";
 
 
 
 
 
 
 
 
 
 
9
  };
10
 
11
+ // export const loginFromCode = async (code: string) => {
12
+ // const request = await fetch(`/api/auth`, {
13
+ // method: "POST",
14
+ // body: JSON.stringify({ code }),
15
+ // });
16
+ // const { ok, token } = await request.json();
17
+ // if (ok) {
18
+ // cookies.set("hf_access_token", token, { expires: 1, domain: process.env.SPACE_HOST });
19
+ // window.location.reload();
20
+ // }
21
+ // };
src/routes/+layout.svelte CHANGED
@@ -1,11 +1,10 @@
1
  <script>
2
  import { get } from "svelte/store";
3
- import { browser } from '$app/environment';
4
  import Icon from "@iconify/svelte";
5
 
6
  import Sidebar from "$lib/components/sidebar/Sidebar.svelte";
7
  import "$lib/styles/tailwind.css"
8
- import { userStore, loginFromCode } from "$lib/stores/use-user";
9
  import Dialog from "$lib/components/dialog/Dialog.svelte";
10
  import { loginModalStore } from "$lib/stores/use-login-modal";
11
 
@@ -17,14 +16,6 @@
17
  loginModalStore.subscribe((v) => {
18
  open = v;
19
  });
20
-
21
- if (browser) {
22
- window.addEventListener("message", async (event) => {
23
- if (event.data?.type === "user-oauth") {
24
- await loginFromCode(event.data.code);
25
- }
26
- });
27
- }
28
  </script>
29
 
30
  <div class="flex items-start">
 
1
  <script>
2
  import { get } from "svelte/store";
 
3
  import Icon from "@iconify/svelte";
4
 
5
  import Sidebar from "$lib/components/sidebar/Sidebar.svelte";
6
  import "$lib/styles/tailwind.css"
7
+ import { userStore } from "$lib/stores/use-user";
8
  import Dialog from "$lib/components/dialog/Dialog.svelte";
9
  import { loginModalStore } from "$lib/stores/use-login-modal";
10
 
 
16
  loginModalStore.subscribe((v) => {
17
  open = v;
18
  });
 
 
 
 
 
 
 
 
19
  </script>
20
 
21
  <div class="flex items-start">
src/routes/login/callback/+page.svelte CHANGED
@@ -1,29 +1,3 @@
1
- <script lang="ts">
2
- import { browser } from '$app/environment';
3
- export let data;
4
-
5
- if (browser && data?.code) {
6
- if (window.opener) {
7
- window.opener.postMessage(
8
- {
9
- code: data?.code,
10
- type: "user-oauth",
11
- },
12
- window.location.origin
13
- );
14
- setTimeout(() => window.close(), 200);
15
- } else {
16
- window.postMessage(
17
- {
18
- code: data?.code,
19
- type: "user-oauth",
20
- },
21
- window.location.origin
22
- );
23
- }
24
- }
25
- </script>
26
-
27
  <div class="p-10">
28
  <h1 class="text-white text-2xl font-bold">Login in progress..</h1>
29
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <div class="p-10">
2
  <h1 class="text-white text-2xl font-bold">Login in progress..</h1>
3
  </div>
src/routes/login/callback/+page.ts CHANGED
@@ -1,6 +1,21 @@
 
 
1
  export async function load({ url }) {
2
  const code = url.searchParams.get("code")
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  return {
5
  code
6
  }
 
1
+ import cookies from "js-cookie";
2
+
3
  export async function load({ url }) {
4
  const code = url.searchParams.get("code")
5
 
6
+ // let token;
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
+ cookies.set("hf_access_token", token, { expires: 1, domain: process.env.SPACE_HOST });
15
+ window.location.href = "/";
16
+ }
17
+ }
18
+
19
  return {
20
  code
21
  }