auth, Users: initial preparation for multi client support

BREAKING CHANGE
This commit is contained in:
Jesse Chan
2020-10-11 00:07:11 +08:00
parent 61002f698b
commit cf08d68c92
35 changed files with 878 additions and 504 deletions
+37
View File
@@ -0,0 +1,37 @@
import * as z from 'zod';
import {AccessLevel, credentialsSchema} 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<z.infer<typeof authAuthenticationSchema>>;
// POST /api/auth/authenticate - success response
export interface AuthAuthenticationResponse {
success: boolean;
token: string;
username: string;
level: AccessLevel;
}
// POST /api/auth/register
export const authRegistrationSchema = credentialsSchema;
export type AuthRegistrationOptions = Required<z.infer<typeof authRegistrationSchema>>;
// PATCH /api/auth/users/{username}
export const authUpdateUserSchema = credentialsSchema.partial();
export type AuthUpdateUserOptions = z.infer<typeof authUpdateUserSchema>;
// GET /api/auth/verify - success response
export type AuthVerificationResponse =
| {
initialUser: true;
}
| {
initialUser: false;
username: string;
level: AccessLevel;
token?: string;
};