Spaces:
Running
Running
different uri
Browse files- app/api/auth/route.ts +13 -3
app/api/auth/route.ts
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
import { NextRequest, NextResponse } from "next/server";
|
2 |
|
3 |
-
export async function GET() {
|
4 |
-
const
|
|
|
|
|
|
|
|
|
|
|
5 |
const loginRedirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.HUGGINGFACE_CLIENT_ID}&redirect_uri=${redirect_uri}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
|
6 |
|
7 |
return NextResponse.json(
|
@@ -37,7 +42,12 @@ export async function POST(req: NextRequest) {
|
|
37 |
`${process.env.HUGGINGFACE_CLIENT_ID}:${process.env.HUGGINGFACE_CLIENT_SECRET}`
|
38 |
).toString("base64")}`;
|
39 |
|
40 |
-
const
|
|
|
|
|
|
|
|
|
|
|
41 |
const request_auth = await fetch("https://huggingface.co/oauth/token", {
|
42 |
method: "POST",
|
43 |
headers: {
|
|
|
1 |
import { NextRequest, NextResponse } from "next/server";
|
2 |
|
3 |
+
export async function GET(req: NextRequest) {
|
4 |
+
const host =
|
5 |
+
req.headers.get("host") ?? req.headers.get("origin") ?? "localhost:3000";
|
6 |
+
const redirect_uri =
|
7 |
+
`${host.includes("localhost") ? "http://" : "https://"}` +
|
8 |
+
host +
|
9 |
+
"/auth/callback";
|
10 |
const loginRedirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.HUGGINGFACE_CLIENT_ID}&redirect_uri=${redirect_uri}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
|
11 |
|
12 |
return NextResponse.json(
|
|
|
42 |
`${process.env.HUGGINGFACE_CLIENT_ID}:${process.env.HUGGINGFACE_CLIENT_SECRET}`
|
43 |
).toString("base64")}`;
|
44 |
|
45 |
+
const host =
|
46 |
+
req.headers.get("host") ?? req.headers.get("origin") ?? "localhost:3000";
|
47 |
+
const redirect_uri =
|
48 |
+
`${host.includes("localhost") ? "http://" : "https://"}` +
|
49 |
+
host +
|
50 |
+
"/auth/callback";
|
51 |
const request_auth = await fetch("https://huggingface.co/oauth/token", {
|
52 |
method: "POST",
|
53 |
headers: {
|