mirror of
https://github.com/zoriya/flood.git
synced 2025-12-05 23:06:20 +00:00
31 lines
905 B
TypeScript
31 lines
905 B
TypeScript
import type {infer as zodInfer} from 'zod';
|
|
import {literal, nativeEnum, number, strictObject, string, union} from 'zod';
|
|
|
|
import {clientConnectionSettingsSchema} from './ClientConnectionSettings';
|
|
import {AccessLevel} from './constants/Auth';
|
|
|
|
export const authMethodSchema = union([literal('default'), literal('none')]);
|
|
|
|
export type AuthMethod = zodInfer<typeof authMethodSchema>;
|
|
|
|
export const credentialsSchema = strictObject({
|
|
username: string(),
|
|
password: string(),
|
|
client: clientConnectionSettingsSchema,
|
|
level: nativeEnum(AccessLevel),
|
|
});
|
|
|
|
export type Credentials = zodInfer<typeof credentialsSchema>;
|
|
|
|
export type UserInDatabase = Required<Credentials> & {_id: string; timestamp: number};
|
|
|
|
export const authTokenSchema = strictObject({
|
|
username: string(),
|
|
// issued at
|
|
iat: number(),
|
|
// expiration
|
|
exp: number(),
|
|
});
|
|
|
|
export type AuthToken = zodInfer<typeof authTokenSchema>;
|