Files
flood/shared/schema/api/auth.ts
2021-10-23 20:52:11 -07:00

57 lines
1.5 KiB
TypeScript

import type {infer as zodInfer} from 'zod';
import {AccessLevel} from '../constants/Auth';
import {credentialsSchema} from '../Auth';
import type {AuthMethod} from '../Auth';
// All auth requests are schema validated to ensure security.
// POST /api/auth/authenticate
export const authAuthenticationSchema = credentialsSchema.pick({
username: true,
password: true,
});
export type AuthAuthenticationOptions = Required<zodInfer<typeof authAuthenticationSchema>>;
// POST /api/auth/authenticate - success response
export interface AuthAuthenticationResponse {
success: boolean;
username: string;
level: AccessLevel;
}
// POST /api/auth/register
export const authRegistrationSchema = credentialsSchema;
export type AuthRegistrationOptions = Required<zodInfer<typeof authRegistrationSchema>>;
// POST /api/auth/register - success response
export interface AuthRegistrationResponse {
username: string;
level: AccessLevel;
}
// PATCH /api/auth/users/{username}
export const authUpdateUserSchema = credentialsSchema.partial();
export type AuthUpdateUserOptions = zodInfer<typeof authUpdateUserSchema>;
// GET /api/auth/verify - preload configurations
export interface AuthVerificationPreloadConfigs {
authMethod: AuthMethod;
pollInterval: number;
}
// GET /api/auth/verify - success response
export type AuthVerificationResponse = (
| {
initialUser: true;
}
| {
initialUser: false;
username: string;
level: AccessLevel;
}
) & {
configs: AuthVerificationPreloadConfigs;
};