Add shared customer auth, cart handoff, and account dropdown.
Mirror Meshkee customer sessions onto the storefront, continue checkout on the customer dashboard, and show profile/orders/admin links under the header name. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
c2552af079
commit
c53fb99330
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
getBearerToken,
|
||||
jsonResponse,
|
||||
meshkeeFetch,
|
||||
unauthorizedResponse,
|
||||
} from "@/lib/meshkee-server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const token = getBearerToken(request);
|
||||
if (!token) return unauthorizedResponse();
|
||||
|
||||
const res = await meshkeeFetch("/auth/addresses", { token });
|
||||
if (!res.ok) return jsonResponse(res.data ?? { error: "Failed" }, res.status);
|
||||
return jsonResponse(res.data);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const token = getBearerToken(request);
|
||||
if (!token) return unauthorizedResponse();
|
||||
|
||||
const body = await request.json().catch(() => null);
|
||||
if (!body?.province || !body?.city || !body?.address) {
|
||||
return jsonResponse({ error: "آدرس کامل الزامی است" }, 400);
|
||||
}
|
||||
|
||||
const res = await meshkeeFetch("/auth/addresses", {
|
||||
method: "POST",
|
||||
token,
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!res.ok) return jsonResponse(res.data ?? { error: "Failed" }, res.status);
|
||||
return jsonResponse(res.data, res.status === 201 ? 201 : 200);
|
||||
}
|
||||
Reference in New Issue
Block a user