forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.ts
More file actions
26 lines (22 loc) · 818 Bytes
/
Copy pathshared.ts
File metadata and controls
26 lines (22 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { NextResponse } from "next/server";
import { normalizeErrorPayload } from "../../../lib/api-errors";
import { fetchApi, getSessionTokenFromCookie } from "../auth/shared";
export async function forwardArenaRequest(path: string, init?: RequestInit) {
const token = await getSessionTokenFromCookie();
if (!token) {
return NextResponse.json(
{ error: "Tu sesion no es valida o ya vencio." },
{ status: 401 },
);
}
const response = await fetchApi(path, {
...init,
headers: {
...(init?.headers ?? {}),
Authorization: `Bearer ${token}`,
},
cache: "no-store",
});
const result = normalizeErrorPayload(await response.json());
return NextResponse.json(result, { status: response.status });
}