Spaces:
Running
Running
another try
Browse filesFiles changed (3)
12345678910111213141516171819202122import { NextResponse } from "next/server";import MY_TOKEN_KEY from "@/lib/get-cookie-name";export async function POST() {const cookieName = MY_TOKEN_KEY();const isProduction = process.env.NODE_ENV === "production";const response = NextResponse.json({ message: "Logged out successfully" },{ status: 200 });// Clear the HTTP-only cookieconst cookieOptions = [`${cookieName}=`,"Max-Age=0","Path=/","HttpOnly",...(isProduction ? ["Secure", "SameSite=None"] : ["SameSite=Lax"])].join("; ");response.headers.set("Set-Cookie", cookieOptions);1234567891011121314151617181920212223import { NextRequest, NextResponse } from "next/server";import MY_TOKEN_KEY from "@/lib/get-cookie-name";export async function POST(req: NextRequest) {const cookieName = MY_TOKEN_KEY();const host = req.headers.get("host") ?? "localhost:3000";const isSecure = !host.includes("localhost");const response = NextResponse.json({ message: "Logged out successfully" },{ status: 200 });// Clear the cookie (matching the same settings as login)const cookieOptions = [`${cookieName}=`,"Max-Age=0","Path=/","SameSite=Lax",...(isSecure ? ["Secure"] : [])].join("; ");response.headers.set("Set-Cookie", cookieOptions);
123465 unmodified lines7071727374754 unmodified lines808182838485import { NextRequest, NextResponse } from "next/server";export async function POST(req: NextRequest) {const body = await req.json();65 unmodified lines}const user = await userResponse.json();return NextResponse.json({access_token: response.access_token,4 unmodified linesstatus: 200,headers: {"Content-Type": "application/json",},});1234565 unmodified lines717273747576777879808182838485864 unmodified lines91929394959697import { NextRequest, NextResponse } from "next/server";import MY_TOKEN_KEY from "@/lib/get-cookie-name";export async function POST(req: NextRequest) {const body = await req.json();65 unmodified lines}const user = await userResponse.json();// Calculate cookie expirationconst expiresIn = response.expires_in || 3600;const maxAge = expiresIn;// Determine if we should use secure cookiesconst isSecure = !host.includes("localhost");// Set the cookie via Set-Cookie headerconst cookieValue = `${MY_TOKEN_KEY()}=${response.access_token}; Path=/; Max-Age=${maxAge}; SameSite=Lax${isSecure ? "; Secure" : ""}`;return NextResponse.json({access_token: response.access_token,4 unmodified linesstatus: 200,headers: {"Content-Type": "application/json","Set-Cookie": cookieValue,},});
55 unmodified lines56575859606162633 unmodified lines67686970717255 unmodified linesasync function getMe() {const cookieStore = await cookies();const token = cookieStore.get(MY_TOKEN_KEY())?.value;console.log("TOKEN IS => ", token);if (!token) return { user: null, projects: [], errCode: null };try {const res = await apiServer.get("/me", {3 unmodified lines});return { user: res.data.user, projects: res.data.projects, errCode: null };} catch (err: any) {return { user: null, projects: [], errCode: err.status };}}55 unmodified lines56575859606162636465666768697071723 unmodified lines7677787980818255 unmodified linesasync function getMe() {const cookieStore = await cookies();const tokenKey = MY_TOKEN_KEY();const token = cookieStore.get(tokenKey)?.value;// Debug loggingconsole.log("π [DEBUG] Cookie Key:", tokenKey);console.log("π [DEBUG] Token found:", !!token);console.log("π [DEBUG] All cookies:",cookieStore.getAll().map((c) => c.name));if (!token) return { user: null, projects: [], errCode: null };try {const res = await apiServer.get("/me", {3 unmodified lines});return { user: res.data.user, projects: res.data.projects, errCode: null };} catch (err: any) {console.error("π [DEBUG] API Error:", err.status, err.message);return { user: null, projects: [], errCode: err.status };}}
app/api/auth/logout/route.ts+7-6
app/api/auth/route.ts+12
app/layout.tsx+12-2