mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
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;
|
|
};
|