added error handling, fixed authenticaton, added toaster
This commit is contained in:
parent
40c35bda13
commit
b6b7cea210
18 changed files with 1327 additions and 68 deletions
33
app/server/graphql/resolvers/auth/signUp.ts
Normal file
33
app/server/graphql/resolvers/auth/signUp.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma, uuid } from '@app/server/prisma/client';
|
||||
import { MutationRegisterArgs } from '@generated/types';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
export async function SignUpResolver(
|
||||
_: any,
|
||||
{ input }: MutationRegisterArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<void> {
|
||||
const existingUsername = await prisma.user.findUnique({
|
||||
where: { username: input.username },
|
||||
select: { id: true }
|
||||
});
|
||||
if (existingUsername != null) throw new Error('User with this username already exists.');
|
||||
|
||||
const existingEmail = await prisma.user.findUnique({
|
||||
where: { email: input.email },
|
||||
select: { id: true }
|
||||
});
|
||||
if (existingEmail != null) throw new Error('Email is already in use.');
|
||||
|
||||
const hashedPassword = await bcrypt.hash(input.password, 10);
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
email: input.email,
|
||||
username: input.username,
|
||||
password: hashedPassword
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue