Feat/navigate to signup if email does not exist (#540)

* Add userExists route

* Fix demo mode for login

* Improve sign in/up flow

* Remove redundant password length constraint

* Fix test
This commit is contained in:
Emilien Chauvet
2023-07-08 15:02:39 -07:00
committed by GitHub
parent 36ace6cc03
commit 9cd5f7c057
10 changed files with 123 additions and 20 deletions

View File

@ -11,6 +11,7 @@ import { PASSWORD_REGEX, compareHash, hashPassword } from '../auth.util';
import { Verify } from '../dto/verify.entity';
import { TokenService } from './token.service';
import { Prisma } from '@prisma/client';
import { UserExists } from '../dto/user-exists.entity';
export type UserPayload = {
firstName: string;
@ -26,18 +27,16 @@ export class AuthService {
) {}
async challenge(challengeInput: ChallengeInput) {
assert(
PASSWORD_REGEX.test(challengeInput.password),
'Password too weak',
BadRequestException,
);
let user = await this.userService.findUnique({
where: {
email: challengeInput.email,
},
});
const isPasswordValid = PASSWORD_REGEX.test(challengeInput.password);
assert(!!user || isPasswordValid, 'Password too weak', BadRequestException);
if (!user) {
const passwordHash = await hashPassword(challengeInput.password);
@ -92,4 +91,14 @@ export class AuthService {
},
};
}
async checkUserExists(email: string): Promise<UserExists> {
const user = await this.userService.findUnique({
where: {
email,
},
});
return { exists: !!user };
}
}