File size: 1,013 Bytes
b1a4d81
7bb6a57
ced6222
b1a4d81
 
 
09bd50c
 
bb7c361
faf0a00
8ba3d1e
ced6222
faf0a00
 
8ba3d1e
 
 
 
 
7bb6a57
 
 
9fceaf0
 
 
 
7bb6a57
 
1d8a7fb
cf40eb5
7bb6a57
09bd50c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { writable } from "svelte/store";
import cookies from "js-cookie";
import { env } from "$env/dynamic/public";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const userStore = writable<any>(null);

export const openWindowLogin = async () => {
  console.log(window)
  if (window.location.host.includes("huggingface.co")) {
    console.log("redirecting to public space", env.PUBLIC_SPACE_URL)
    window.location.href = env.PUBLIC_SPACE_URL as string;
    return
  }
  return window.open(
    "/api/auth/login",
    "Login to LoRAs Studio",
    "menubar=no,width=500,height=777,location=no,resizable=no,scrollbars=yes,status=no"
  );
};

export const loginFromCode = async (code: string) => {
  const request = await fetch(`/api/auth`, {
    method: "POST",
    body: JSON.stringify({ code }),
  });
  const { ok, token } = await request.json();
  if (ok) {
    cookies.set("hf_access_token", token, { expires: 1, domain: process.env.SPACE_HOST });
    window.location.reload();
  }
};