Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
522ddd5
1
Parent(s):
ddbf0ae
debugging..
Browse files
src/app/api/login/route.ts
CHANGED
@@ -1,13 +1,59 @@
|
|
|
|
1 |
import { NextResponse, NextRequest } from "next/server"
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
export async function GET(req: NextRequest) {
|
|
|
|
|
|
|
4 |
console.log("Received GET /api/login:", req.url)
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
}
|
7 |
|
8 |
export async function POST(req: NextRequest, res: NextResponse) {
|
9 |
-
const
|
10 |
-
|
11 |
console.log("Received POST /api/login:", req.url)
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
|
|
1 |
+
import querystring from "node:querystring"
|
2 |
import { NextResponse, NextRequest } from "next/server"
|
3 |
|
4 |
+
const defaultState = JSON.stringify({
|
5 |
+
nonce: "",
|
6 |
+
redirectUri: "https://aitube.at/api/login",
|
7 |
+
state: JSON.stringify({ redirectTo: "/" })
|
8 |
+
})
|
9 |
+
|
10 |
export async function GET(req: NextRequest) {
|
11 |
+
|
12 |
+
const query = querystring.parse(req.url)
|
13 |
+
|
14 |
console.log("Received GET /api/login:", req.url)
|
15 |
+
console.log(query)
|
16 |
+
|
17 |
+
|
18 |
+
// we are only interested in our own data, actually
|
19 |
+
// const code = `${query.code || ""}` // <-- ignored, we will send it as-is
|
20 |
+
const {
|
21 |
+
// nonce, // <-- ignored, we will send it as-is
|
22 |
+
// redirectUri, // <-- ignored, we will send it as-is
|
23 |
+
state // <-- this is defined by us!
|
24 |
+
} = JSON.parse(`${query.state || defaultState}`)
|
25 |
+
|
26 |
+
// this is the path of the AI Tube page which the user was browser
|
27 |
+
// eg. this can be /account, /, or nothing
|
28 |
+
const redirectTo = `${state.redirectTo || "/"}`
|
29 |
+
|
30 |
+
// we are going to pass the whole thing unchanged to the AI Tube frontend
|
31 |
+
const rest = req.url.split("/api/login").pop()
|
32 |
+
|
33 |
+
return NextResponse.redirect(`https://aitube.at${redirectTo}${rest}`)
|
34 |
}
|
35 |
|
36 |
export async function POST(req: NextRequest, res: NextResponse) {
|
37 |
+
const query = querystring.parse(req.url)
|
38 |
+
|
39 |
console.log("Received POST /api/login:", req.url)
|
40 |
+
console.log(query)
|
41 |
+
|
42 |
+
|
43 |
+
// we are only interested in our own data, actually
|
44 |
+
// const code = `${query.code || ""}` // <-- ignored, we will send it as-is
|
45 |
+
const {
|
46 |
+
// nonce, // <-- ignored, we will send it as-is
|
47 |
+
// redirectUri, // <-- ignored, we will send it as-is
|
48 |
+
state // <-- this is defined by us!
|
49 |
+
} = JSON.parse(`${query.state || defaultState}`)
|
50 |
+
|
51 |
+
// this is the path of the AI Tube page which the user was browser
|
52 |
+
// eg. this can be /account, /, or nothing
|
53 |
+
const redirectTo = `${state.redirectTo || "/"}`
|
54 |
+
|
55 |
+
// we are going to pass the whole thing unchanged to the AI Tube frontend
|
56 |
+
const rest = req.url.split("/api/login").pop()
|
57 |
+
|
58 |
+
return NextResponse.redirect(`https://aitube.at${redirectTo}${rest}`)
|
59 |
}
|
src/app/state/userCurrentUser.ts
CHANGED
@@ -92,7 +92,7 @@ export function useCurrentUser({
|
|
92 |
// (depending on if it's a secret page or not)
|
93 |
|
94 |
if (isLoginRequired) {
|
95 |
-
await login()
|
96 |
}
|
97 |
|
98 |
return undefined
|
|
|
92 |
// (depending on if it's a secret page or not)
|
93 |
|
94 |
if (isLoginRequired) {
|
95 |
+
await login("/")
|
96 |
}
|
97 |
|
98 |
return undefined
|