Add user login, signup, and session.
This commit is contained in:
parent
3be05a9752
commit
f5466faa70
6 changed files with 101 additions and 36 deletions
11
app/api/users/login/route.ts
Normal file
11
app/api/users/login/route.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const BACKEND_URL = process.env.BACKEND_URL;
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const response = await fetch(`${BACKEND_URL}/users/token`, request);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return Response.json(data, {
|
||||
status: response.status,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,32 +1,25 @@
|
|||
const BACKEND_URL = process.env.BACKEND_URL;
|
||||
|
||||
export async function GET() {
|
||||
const response = await fetch(`${BACKEND_URL}/users`);
|
||||
const response = await fetch(`${BACKEND_URL}/users`);
|
||||
|
||||
if (!response.ok) {
|
||||
return new Response("Request failed in backend", { status: response.status, });
|
||||
}
|
||||
if (!response.ok) {
|
||||
return new Response("Request failed in backend", {
|
||||
status: response.status,
|
||||
});
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const data = await response.json();
|
||||
|
||||
return Response.json(data);
|
||||
return Response.json(data);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const response = await fetch(`${BACKEND_URL}/users`, request);
|
||||
|
||||
const body = await request.json();
|
||||
const data = await response.json();
|
||||
|
||||
const response = await fetch(`${BACKEND_URL}/users`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return Response.json(data, {
|
||||
status: response.status,
|
||||
});
|
||||
}
|
||||
return Response.json(data, {
|
||||
status: response.status,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue