enzostvs HF Staff commited on
Commit
9d4895e
·
1 Parent(s): 413679b

try to redirect login in new tab

Browse files
Files changed (2) hide show
  1. server.js +10 -4
  2. src/components/login/login.tsx +8 -3
server.js CHANGED
@@ -42,10 +42,16 @@ const getPTag = (repoId) => {
42
  };
43
 
44
  app.get("/api/login", (_req, res) => {
45
- res.redirect(
46
- 302,
47
- `https://huggingface.co/oauth/authorize?client_id=${process.env.OAUTH_CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`
48
- );
 
 
 
 
 
 
49
  });
50
  app.get("/auth/login", async (req, res) => {
51
  const { code } = req.query;
 
42
  };
43
 
44
  app.get("/api/login", (_req, res) => {
45
+ // res.redirect(
46
+ // 302,
47
+ // `https://huggingface.co/oauth/authorize?client_id=${process.env.OAUTH_CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`
48
+ // );
49
+ // redirect in new tab
50
+ const redirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.OAUTH_CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
51
+ res.status(200).send({
52
+ ok: true,
53
+ redirectUrl,
54
+ });
55
  });
56
  app.get("/auth/login", async (req, res) => {
57
  const { code } = req.query;
src/components/login/login.tsx CHANGED
@@ -10,10 +10,15 @@ function Login({
10
  }) {
11
  const [, setStorage] = useLocalStorage("html_content");
12
 
13
- const handleClick = () => {
14
  if (html !== defaultHTML) {
15
  setStorage(html);
16
  }
 
 
 
 
 
17
  };
18
 
19
  return (
@@ -26,13 +31,13 @@ function Login({
26
  </header>
27
  <main className="px-4 py-4 space-y-3">
28
  {children}
29
- <a href="/api/login" onClick={handleClick}>
30
  <img
31
  src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg"
32
  alt="Sign in with Hugging Face"
33
  className="mx-auto"
34
  />
35
- </a>
36
  </main>
37
  </>
38
  );
 
10
  }) {
11
  const [, setStorage] = useLocalStorage("html_content");
12
 
13
+ const handleClick = async () => {
14
  if (html !== defaultHTML) {
15
  setStorage(html);
16
  }
17
+ const request = await fetch("/api/login");
18
+ const res = await request.json();
19
+ if (res?.redirectUrl) {
20
+ window.open(res.redirectUrl, "_blank");
21
+ }
22
  };
23
 
24
  return (
 
31
  </header>
32
  <main className="px-4 py-4 space-y-3">
33
  {children}
34
+ <button onClick={handleClick}>
35
  <img
36
  src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg"
37
  alt="Sign in with Hugging Face"
38
  className="mx-auto"
39
  />
40
+ </button>
41
  </main>
42
  </>
43
  );