feat(api): add user search endpoint and normalize response data and validation
This commit is contained in:
parent
b5dfe9a4e3
commit
8207230886
4 changed files with 40 additions and 7 deletions
|
@ -21,6 +21,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ZodErrorResponse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"success": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Error message"
|
||||||
|
},
|
||||||
|
"errors": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"path": { "type": "string" },
|
||||||
|
"message": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"User": {
|
"User": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -30,7 +53,9 @@
|
||||||
"last_name": { "type": "string" },
|
"last_name": { "type": "string" },
|
||||||
"email": { "type": "string", "format": "email" },
|
"email": { "type": "string", "format": "email" },
|
||||||
"image": { "type": "string", "format": "uri" },
|
"image": { "type": "string", "format": "uri" },
|
||||||
"timezone": { "type": "string", "description": "User timezone" }
|
"timezone": { "type": "string", "description": "User timezone" },
|
||||||
|
"created_at": { "type": "string", "format": "date-time" },
|
||||||
|
"updated_at": { "type": "string", "format": "date-time" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"PublicUser": {
|
"PublicUser": {
|
||||||
|
@ -76,9 +101,17 @@
|
||||||
"participants": {
|
"participants": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/components/schemas/Participant"
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"user": {
|
||||||
|
"$ref": "#/components/schemas/SimpleUser"
|
||||||
|
},
|
||||||
|
"status": { "type": "string" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"created_at": { "type": "string", "format": "date-time" },
|
||||||
|
"updated_at": { "type": "string", "format": "date-time" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ const providers: Provider[] = [
|
||||||
if (process.env.DISABLE_PASSWORD_LOGIN) return null;
|
if (process.env.DISABLE_PASSWORD_LOGIN) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { email, password } = await loginSchema.parseAsync(c);
|
const { email, password } = await loginClientSchema.parseAsync(c);
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: { OR: [{ email }, { name: email }] },
|
where: { OR: [{ email }, { name: email }] },
|
||||||
|
|
|
@ -18,7 +18,7 @@ function LoginFormElement({
|
||||||
formRef?: React.RefObject<HTMLFormElement | null>;
|
formRef?: React.RefObject<HTMLFormElement | null>;
|
||||||
}) {
|
}) {
|
||||||
const { handleSubmit, formState, register, setError } =
|
const { handleSubmit, formState, register, setError } =
|
||||||
useZodForm(loginSchema);
|
useZodForm(loginClientSchema);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
|
@ -95,7 +95,7 @@ function RegisterFormElement({
|
||||||
formRef?: React.RefObject<HTMLFormElement | null>;
|
formRef?: React.RefObject<HTMLFormElement | null>;
|
||||||
}) {
|
}) {
|
||||||
const { handleSubmit, formState, register, setError } =
|
const { handleSubmit, formState, register, setError } =
|
||||||
useZodForm(registerSchema);
|
useZodForm(registerClientSchema);
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { z } from 'zod/v4';
|
||||||
import { loginSchema } from './validation';
|
import { loginSchema } from './validation';
|
||||||
import { signIn } from '@/auth';
|
import { signIn } from '@/auth';
|
||||||
|
|
||||||
export async function loginAction(data: z.infer<typeof loginSchema>) {
|
export async function loginAction(data: z.infer<typeof loginClientSchema>) {
|
||||||
try {
|
try {
|
||||||
await signIn('credentials', {
|
await signIn('credentials', {
|
||||||
...data,
|
...data,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue