Skip to content
This repository was archived by the owner on Nov 29, 2021. It is now read-only.

Commit cd04fe1

Browse files
feat: check is repeat of username when register
1 parent d6bf445 commit cd04fe1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/auth/auth.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ export class AuthService {
5656

5757
public async register(registerInput: RegisterInput) {
5858
const { email, username } = registerInput
59-
const curEmail = await this.usersService.findOneByEmail(email)
59+
const curUserByEmail = await this.usersService.findOneByEmail(email)
60+
const curUserByUserName = await this.usersService.findOneByUserName(username)
6061

61-
if (curEmail) {
62-
throw new ForbiddenError('Email is already registered!')
62+
if (curUserByEmail) {
63+
throw new ForbiddenError('Email has already been used, Please enter another one.')
64+
} else if (curUserByUserName) {
65+
throw new ForbiddenError('UserName has already been used, Please enter another one.')
6366
} else {
64-
// TODO: 通过脚本初始化 root 用户
6567
const count = await this.usersService.getUserCount()
6668
const params = count === 0 ? { ...registerInput, role: Roles.SUPERUSER } : registerInput
6769
const res = await this.usersService.create({ ...params })

0 commit comments

Comments
 (0)