File size: 845 Bytes
cbc1bda
 
 
 
4c9a7ca
 
da7585f
4c9a7ca
da7585f
 
 
 
4c9a7ca
 
cbc1bda
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { NextRequest, NextResponse } from "next/server";

export async function GET(req: NextRequest) {
  const host = req.headers.get("host") ?? "localhost:3000";
  
  let url: string;
  if (host.includes("localhost")) {
    url = host;
  } else if (host.includes("hf.space") || host.includes("/spaces/enzostvs")) {
    url = "enzostvs-deepsite.hf.space";
  } else {
    url = "deepsite.hf.co";
  }
  
  const redirect_uri =
    `${host.includes("localhost") ? "http://" : "https://"}` +
    url +
    "/auth/callback";

  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`;
  
  return NextResponse.json({ loginUrl: loginRedirectUrl });
}