20 lines
677 B
TypeScript
20 lines
677 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getAuthToken, medusaAuthFetch } from "@/lib/auth";
|
|
import { cookies } from "next/headers";
|
|
|
|
export async function GET() {
|
|
const token = await getAuthToken();
|
|
if (!token) {
|
|
return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const data = await medusaAuthFetch<{ customer: unknown }>("/store/customers/me");
|
|
return NextResponse.json(data);
|
|
} catch {
|
|
// Token expired or invalid — clear the cookie
|
|
const cookieStore = await cookies();
|
|
cookieStore.delete("medusa_auth_token");
|
|
return NextResponse.json({ error: "Session expired" }, { status: 401 });
|
|
}
|
|
}
|