fix: admin users were created while the setup wizard wasn't finished

This commit is contained in:
Elias Schneider
2023-01-26 15:43:13 +01:00
parent 7e91038a24
commit ad92cfc852
8 changed files with 37 additions and 22 deletions

View File

@@ -23,6 +23,8 @@ export class AuthService {
) {}
async signUp(dto: AuthRegisterDTO) {
const isFirstUser = this.config.get("SETUP_STATUS") == "STARTED";
const hash = await argon.hash(dto.password);
try {
const user = await this.prisma.user.create({
@@ -30,10 +32,14 @@ export class AuthService {
email: dto.email,
username: dto.username,
password: hash,
isAdmin: !this.config.get("SETUP_FINISHED"),
isAdmin: isFirstUser,
},
});
if (isFirstUser) {
await this.config.changeSetupStatus("REGISTERED");
}
const { refreshToken, refreshTokenId } = await this.createRefreshToken(
user.id
);