feat: onboarding & profile edition (#507)

* feat: wip onboarding

* fix: generate graphql front

* wip: onboarding

* feat: login/register and edit profile

* fix: unused import

* fix: test

* Use DEBUG_MODE instead of STAGE and mute typescript depth exceed errors

* Fix seeds

* Fix onboarding when coming from google

* Fix

* Fix lint

* Fix ci

* Fix tests

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2023-07-07 02:05:15 +02:00
committed by GitHub
parent 0b7a023f3d
commit 1144bd13ed
141 changed files with 2660 additions and 962 deletions

View File

@ -7,7 +7,6 @@ import {
import { ChallengeInput } from '../dto/challenge.input';
import { UserService } from 'src/core/user/user.service';
import { assert } from 'src/utils/assert';
import { RegisterInput } from '../dto/register.input';
import { PASSWORD_REGEX, compareHash, hashPassword } from '../auth.util';
import { Verify } from '../dto/verify.entity';
import { TokenService } from './token.service';
@ -26,42 +25,31 @@ export class AuthService {
private readonly userService: UserService,
) {}
async register(registerInput: RegisterInput) {
const existingUser = await this.userService.findUnique({
where: {
email: registerInput.email,
},
});
assert(!existingUser, 'This user already exist', NotFoundException);
async challenge(challengeInput: ChallengeInput) {
assert(
PASSWORD_REGEX.test(registerInput.password),
PASSWORD_REGEX.test(challengeInput.password),
'Password too weak',
BadRequestException,
);
const passwordHash = await hashPassword(registerInput.password);
const user = await this.userService.createUser({
data: {
firstName: registerInput.firstName,
lastName: registerInput.lastName,
email: registerInput.email,
passwordHash,
locale: 'en',
},
});
return user;
}
async challenge(challengeInput: ChallengeInput) {
const user = await this.userService.findUnique({
let user = await this.userService.findUnique({
where: {
email: challengeInput.email,
},
});
if (!user) {
const passwordHash = await hashPassword(challengeInput.password);
user = await this.userService.createUser({
data: {
email: challengeInput.email,
passwordHash,
locale: 'en',
},
} as Prisma.UserCreateArgs);
}
assert(user, "This user doesn't exist", NotFoundException);
assert(user.passwordHash, 'Incorrect login method', ForbiddenException);