40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
export const LoginDtoSchema = z.object({
|
|
username: z.string().min(1).max(64),
|
|
password: z.string().min(1).max(256),
|
|
});
|
|
export type LoginDto = z.infer<typeof LoginDtoSchema>;
|
|
|
|
export const RefreshDtoSchema = z.object({
|
|
refreshToken: z.string().min(1).optional(),
|
|
});
|
|
export type RefreshDto = z.infer<typeof RefreshDtoSchema>;
|
|
|
|
export const CsrfResponseDtoSchema = z.object({
|
|
csrfToken: z.string(),
|
|
});
|
|
export type CsrfResponseDto = z.infer<typeof CsrfResponseDtoSchema>;
|
|
|
|
export const RegisterDtoSchema = z
|
|
.object({
|
|
username: z
|
|
.string()
|
|
.min(3)
|
|
.max(32)
|
|
.regex(/^[a-zA-Z0-9_.-]+$/, 'Username may only contain letters, digits, dot, dash and underscore'),
|
|
password: z.string().min(1).max(256),
|
|
passwordConfirm: z.string().min(1).max(256),
|
|
})
|
|
.refine((d) => d.password === d.passwordConfirm, {
|
|
path: ['passwordConfirm'],
|
|
message: 'Passwords do not match',
|
|
});
|
|
export type RegisterDto = z.infer<typeof RegisterDtoSchema>;
|
|
|
|
export interface LoginResponse {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
expiresIn: number;
|
|
user: { id: string; username: string; role: 'admin' | 'player' };
|
|
} |