Browse Source

Feature/refactor validateAnonymousLogin to simplify promise handling

pull/5981/head
Germán Martín 3 weeks ago
parent
commit
d9f5e79a5d
  1. 36
      apps/api/src/app/auth/auth.service.ts

36
apps/api/src/app/auth/auth.service.ts

@ -17,30 +17,22 @@ export class AuthService {
) {} ) {}
public async validateAnonymousLogin(accessToken: string): Promise<string> { public async validateAnonymousLogin(accessToken: string): Promise<string> {
return new Promise(async (resolve, reject) => { const hashedAccessToken = this.userService.createAccessToken({
try { password: accessToken,
const hashedAccessToken = this.userService.createAccessToken({ salt: this.configurationService.get('ACCESS_TOKEN_SALT')
password: accessToken, });
salt: this.configurationService.get('ACCESS_TOKEN_SALT')
});
const [user] = await this.userService.users({ const [user] = await this.userService.users({
where: { accessToken: hashedAccessToken } where: { accessToken: hashedAccessToken }
}); });
if (user) { if (user) {
const jwt = this.jwtService.sign({ return this.jwtService.sign({
id: user.id id: user.id
}); });
}
resolve(jwt); throw new Error();
} else {
throw new Error();
}
} catch {
reject();
}
});
} }
public async validateOAuthLogin({ public async validateOAuthLogin({
@ -75,7 +67,7 @@ export class AuthService {
} catch (error) { } catch (error) {
throw new InternalServerErrorException( throw new InternalServerErrorException(
'validateOAuthLogin', 'validateOAuthLogin',
error.message error instanceof Error ? error.message : 'Unknown error'
); );
} }
} }

Loading…
Cancel
Save