mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 01:06:23 +02:00
organize auth apis
This commit is contained in:
parent
54d29c6064
commit
c8fae413d2
2 changed files with 76 additions and 0 deletions
55
surfsense_web/lib/apis/auth.api.ts
Normal file
55
surfsense_web/lib/apis/auth.api.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
export const login = async (request: {
|
||||
username: string;
|
||||
password: string;
|
||||
grant_type?: string;
|
||||
}) => {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/auth/jwt/login`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: request.username,
|
||||
password: request.password,
|
||||
grant_type: request.grant_type || "password",
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.detail || `HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const register = async (request: {
|
||||
email: string;
|
||||
password: string;
|
||||
is_active: boolean;
|
||||
is_superuser: boolean;
|
||||
is_verified: boolean;
|
||||
}) => {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/auth/register`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
}
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.detail || `HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue