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:
@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user