mirror of
https://github.com/StepanovPlaton/torrent_frontend.git
synced 2026-04-03 12:20:48 +04:00
Add login
This commit is contained in:
30
src/entities/user/schemas/auth.ts
Normal file
30
src/entities/user/schemas/auth.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { z } from "zod";
|
||||
import { userSchema } from "./user";
|
||||
|
||||
export const loginFormSchema = z.object({
|
||||
username: z.string().min(3, "Логин слишком короткий"),
|
||||
password: z.string().min(3, "Пароль слишком короткий"),
|
||||
});
|
||||
export const loginFormFieldNames = {
|
||||
username: "Логин",
|
||||
password: "Пароль",
|
||||
};
|
||||
export type LoginForm = z.infer<typeof loginFormSchema>;
|
||||
|
||||
export const tokenResponseSchema = z
|
||||
.object({
|
||||
access_token: z.string(),
|
||||
token_type: z.string(),
|
||||
})
|
||||
.transform((tokenResponse) => tokenResponse.access_token);
|
||||
export type TokenResponse = z.infer<typeof tokenResponseSchema>;
|
||||
|
||||
export const tokenDataSchema = userSchema.merge(
|
||||
z.object({
|
||||
expire: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform((d) => new Date(d)),
|
||||
})
|
||||
);
|
||||
export type TokenData = z.infer<typeof tokenDataSchema>;
|
||||
Reference in New Issue
Block a user