frontend/app/auth/Session.ts
2026-03-15 09:03:40 +01:00

39 lines
878 B
TypeScript

import {type AxiosResponse} from "axios";
import {Api} from "~/utils/Api";
import type {Account} from "~/auth/Account";
export class Session
{
static baseURL = "http://localhost:8089";
static COOKIE = "session";
constructor(
public user: Account,
public token: string
)
{
}
static create(sessionCreation: SessionCreation, onSuccess: (token: string) => void, onError: () => void)
{
AuthApi.create().post<string>("/sessions/" + useRuntimeConfig().public.clientId, sessionCreation)
.then((response: AxiosResponse) =>
{
onSuccess(response.data);
})
.catch(() =>
{
onError();
});
}
}
export class SessionCreation
{
constructor(
public email?: string,
public password?: string
)
{
}
}