Files
sign/packages/trpc/server/auth-router/router.ts

29 lines
897 B
TypeScript
Raw Normal View History

2023-06-09 18:21:18 +10:00
import { TRPCError } from '@trpc/server';
import { createUser } from '@documenso/lib/server-only/user/create-user';
import { procedure, router } from '../trpc';
import { ZSignUpMutationSchema } from './schema';
export const authRouter = router({
signup: procedure.input(ZSignUpMutationSchema).mutation(async ({ input }) => {
try {
2023-09-01 19:46:44 +10:00
const { name, email, password, signature } = input;
2023-06-09 18:21:18 +10:00
2023-09-01 19:46:44 +10:00
return await createUser({ name, email, password, signature });
2023-06-09 18:21:18 +10:00
} catch (err) {
let message =
'We were unable to create your account. Please review the information you provided and try again.';
if (err instanceof Error && err.message === 'User already exists') {
message = 'User with this email already exists. Please use a different email address.';
}
2023-06-09 18:21:18 +10:00
throw new TRPCError({
code: 'BAD_REQUEST',
message,
2023-06-09 18:21:18 +10:00
});
}
}),
});