44 lines
912 B
TypeScript
44 lines
912 B
TypeScript
import routes from "@/routes";
|
|
import { AuthToken } from "../types";
|
|
import { User } from "./User";
|
|
import { getBaseHeaders } from "../utils";
|
|
|
|
export interface PayloadRegisterByEmail {
|
|
email: string;
|
|
timezone: string;
|
|
locale: string;
|
|
}
|
|
|
|
export interface PayloadAuthWithJWT {
|
|
jwt: string;
|
|
}
|
|
|
|
export type Payload = PayloadRegisterByEmail | PayloadAuthWithJWT;
|
|
|
|
export interface Response {
|
|
auth: {
|
|
token: AuthToken;
|
|
payload: JwtPayload;
|
|
user: User;
|
|
};
|
|
}
|
|
|
|
export interface JwtPayload {
|
|
sub: number;
|
|
email: string;
|
|
loc: string;
|
|
tz: number;
|
|
state: string;
|
|
iat: number;
|
|
exp: number;
|
|
jti: string;
|
|
type: string;
|
|
iss: string;
|
|
}
|
|
|
|
export const createRequest = (payload: Payload): Request => {
|
|
const url = new URL(routes.server.token());
|
|
const body = JSON.stringify({ auth: { ...payload } });
|
|
return new Request(url, { method: "POST", headers: getBaseHeaders(), body });
|
|
};
|