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>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
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);
|
|
}
|