enzostvs HF Staff commited on
Commit
189ab98
·
1 Parent(s): 990a158
app/actions/auth.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use server";
2
+
3
+ import { headers } from "next/headers";
4
+
5
+ export async function getAuth() {
6
+ const authList = await headers();
7
+ const host = authList.get("host") ?? "localhost:3000";
8
+ const redirect_uri =
9
+ `${host.includes("localhost") ? "http://" : "https://"}` +
10
+ host +
11
+ "/auth/callback";
12
+
13
+ const loginRedirectUrl = `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`;
14
+ return loginRedirectUrl;
15
+ }
app/api/auth/route.ts CHANGED
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from "next/server";
2
 
3
  export async function GET(req: NextRequest) {
4
  const host = req.headers.get("host") ?? "localhost:3000";
5
- console.log(req.nextUrl);
6
 
7
  const redirect_uri =
8
  `${host.includes("localhost") ? "http://" : "https://"}` +
 
2
 
3
  export async function GET(req: NextRequest) {
4
  const host = req.headers.get("host") ?? "localhost:3000";
 
5
 
6
  const redirect_uri =
7
  `${host.includes("localhost") ? "http://" : "https://"}` +
app/auth/callback/page.tsx CHANGED
@@ -1,10 +1,10 @@
1
  "use client";
 
2
  import { useUser } from "@/hooks/useUser";
3
  import { use, useState } from "react";
4
  import { useMount, useTimeoutFn } from "react-use";
5
 
6
  import { Button } from "@/components/ui/button";
7
- import Link from "next/link";
8
  export default function AuthCallback({
9
  searchParams,
10
  }: {
 
1
  "use client";
2
+ import Link from "next/link";
3
  import { useUser } from "@/hooks/useUser";
4
  import { use, useState } from "react";
5
  import { useMount, useTimeoutFn } from "react-use";
6
 
7
  import { Button } from "@/components/ui/button";
 
8
  export default function AuthCallback({
9
  searchParams,
10
  }: {
app/auth/page.tsx CHANGED
@@ -1,16 +1,7 @@
1
  import { redirect } from "next/navigation";
2
  import { Metadata } from "next";
3
 
4
- import { apiServer } from "@/lib/api";
5
-
6
- async function getLoginUrl() {
7
- try {
8
- const res = await apiServer.get("/auth");
9
- return res.data;
10
- } catch (error) {
11
- return error;
12
- }
13
- }
14
 
15
  export const revalidate = 1;
16
 
@@ -19,9 +10,9 @@ export const metadata: Metadata = {
19
  };
20
 
21
  export default async function Auth() {
22
- const login = await getLoginUrl();
23
- if (login?.redirect) {
24
- redirect(login.redirect);
25
  }
26
 
27
  return (
 
1
  import { redirect } from "next/navigation";
2
  import { Metadata } from "next";
3
 
4
+ import { getAuth } from "@/app/actions/auth";
 
 
 
 
 
 
 
 
 
5
 
6
  export const revalidate = 1;
7
 
 
10
  };
11
 
12
  export default async function Auth() {
13
+ const loginRedirectUrl = await getAuth();
14
+ if (loginRedirectUrl) {
15
+ redirect(loginRedirectUrl);
16
  }
17
 
18
  return (