Spaces:
Running
Running
test cookie
Browse files- app/api/auth/route.ts +9 -0
- hooks/useUser.ts +8 -7
app/api/auth/route.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
2 |
|
3 |
export async function GET() {
|
4 |
const redirect_uri = process.env.REDIRECT_URI;
|
@@ -77,6 +79,13 @@ export async function POST(req: NextRequest) {
|
|
77 |
);
|
78 |
}
|
79 |
const user = await userResponse.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
return NextResponse.json(
|
82 |
{
|
|
|
1 |
import { NextRequest, NextResponse } from "next/server";
|
2 |
+
import { cookies } from "next/headers";
|
3 |
+
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
4 |
|
5 |
export async function GET() {
|
6 |
const redirect_uri = process.env.REDIRECT_URI;
|
|
|
79 |
);
|
80 |
}
|
81 |
const user = await userResponse.json();
|
82 |
+
const cookieStore = await cookies();
|
83 |
+
cookieStore.set(MY_TOKEN_KEY(), response.access_token, {
|
84 |
+
maxAge: response.expires_in,
|
85 |
+
httpOnly: false,
|
86 |
+
secure: true,
|
87 |
+
sameSite: "none",
|
88 |
+
});
|
89 |
|
90 |
return NextResponse.json(
|
91 |
{
|
hooks/useUser.ts
CHANGED
@@ -60,13 +60,14 @@ export const useUser = (initialData?: {
|
|
60 |
.post("/auth", { code })
|
61 |
.then(async (res: any) => {
|
62 |
if (res.data) {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
70 |
client.setQueryData(["user.me"], {
|
71 |
user: res.data.user,
|
72 |
errCode: null,
|
|
|
60 |
.post("/auth", { code })
|
61 |
.then(async (res: any) => {
|
62 |
if (res.data) {
|
63 |
+
// fix to be able to set the cookie through the space (Hugging Face)
|
64 |
+
// setCookie(res.data.access_token, {
|
65 |
+
// expires: res.data.expires_in
|
66 |
+
// ? new Date(Date.now() + res.data.expires_in * 1000)
|
67 |
+
// : undefined,
|
68 |
+
// sameSite: "none",
|
69 |
+
// secure: true,
|
70 |
+
// });
|
71 |
client.setQueryData(["user.me"], {
|
72 |
user: res.data.user,
|
73 |
errCode: null,
|