Spaces:
Running
Running
test
Browse filesFiles changed (7)
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);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);
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,},});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",},});
55 unmodified lines565758596061626364656667686970712 unmodified lines74757677787980818255 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 {2 unmodified linesAuthorization: `Bearer ${token}`,},});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 };}}55 unmodified lines56575859606162632 unmodified lines6667686970717273747555 unmodified linesasync function getMe() {const cookieStore = await cookies();const cookieName = MY_TOKEN_KEY();const token = cookieStore.get(cookieName)?.value;if (!token) return { user: null, projects: [], errCode: null };try {2 unmodified linesAuthorization: `Bearer ${token}`,},});console.log("✅ [Server] User authenticated:", res.data.user?.name);return { user: res.data.user, projects: res.data.projects, errCode: null };} catch (err: any) {console.error("❌ [Server] Auth error:", err.status, err.message);return { user: null, projects: [], errCode: err.status };}}
130 unmodified lines131132133134135136137130 unmodified lines.background__noisy {@apply bg-blend-normal pointer-events-none opacity-90;background-size: 25ww auto;background-image: url("/background_noisy.webp");@apply fixed w-screen h-screen -z-1 top-0 left-0;}130 unmodified lines131132133134135136137130 unmodified lines.background__noisy {@apply bg-blend-normal pointer-events-none opacity-90;background-size: 25ww auto;background-image: url("/deepsite/background_noisy.webp");@apply fixed w-screen h-screen -z-1 top-0 left-0;}
263 unmodified lines264265266267268269270263 unmodified lines<BrainIcon className="size-4 mr-2" />) : (<Imagesrc={`/providers/${id}.svg`}alt={id}className="size-5 mr-2"width={20}263 unmodified lines264265266267268269270263 unmodified lines<BrainIcon className="size-4 mr-2" />) : (<Imagesrc={`/deepsite/providers/${id}.svg`}alt={id}className="size-5 mr-2"width={20}
74 unmodified lines7576777879808182838485866 unmodified lines9394959697989910010110210310474 unmodified linesconst expiresDate = new Date();expiresDate.setTime(expiresDate.getTime() + expiresIn * 1000);setToken(res.data.access_token, {expires: expiresDate,path: '/',sameSite: 'lax',secure: window.location.protocol === 'https:',});const meResponse = await api.get("/me");if (meResponse.data) {6 unmodified lines}}// if (currentRoute) {// router.push(currentRoute);// removeCurrentRoute();// } else {router.push("/");// }toast.success("Login successful");}})74 unmodified lines75767778798081828384858687888990919293946 unmodified lines10110210310410510610710810911074 unmodified linesconst expiresDate = new Date();expiresDate.setTime(expiresDate.getTime() + expiresIn * 1000);const cookieOptions: any = {expires: expiresDate,path: '/',sameSite: 'lax',};if (window.location.protocol === 'https:') {cookieOptions.secure = true;}setToken(res.data.access_token, cookieOptions);const cookieString = `${MY_TOKEN_KEY()}=${res.data.access_token}; path=/; max-age=${expiresIn}; samesite=lax${cookieOptions.secure ? '; secure' : ''}`;document.cookie = cookieString;const meResponse = await api.get("/me");if (meResponse.data) {6 unmodified lines}}setTimeout(() => {window.location.href = "/";}, 100);toast.success("Login successful");}})
5 unmodified lines678910111 unmodified line1314151617185 unmodified linesheaders: {cache: "no-store",},});export const apiServer = axios.create({1 unmodified lineheaders: {cache: "no-store",},});api.interceptors.request.use(async (config) => {5 unmodified lines67891011121 unmodified line141516171819205 unmodified linesheaders: {cache: "no-store",},withCredentials: true, // Ensure cookies are sent with requests});export const apiServer = axios.create({1 unmodified lineheaders: {cache: "no-store",},withCredentials: true, // Ensure cookies are sent with requests});api.interceptors.request.use(async (config) => {
app/api/auth/logout/route.ts+6-7
app/api/auth/route.ts-12
app/layout.tsx+4-11
assets/globals.css+1-1
components/editor/ask-ai/settings.tsx+1-1
hooks/useUser.ts+15-9
lib/api.ts+2