refactor(api): remove deprecated function and rename exception

This commit is contained in:
Julian Tölle 2021-06-22 20:34:55 +02:00
parent 5ef650a6dc
commit 73bba4ef68
2 changed files with 3 additions and 23 deletions

View file

@ -30,7 +30,7 @@ export class AuthService {
profile, profile,
}: LoginDto): Promise<User> { }: LoginDto): Promise<User> {
if (!this.allowedByUserFilter(profile.id)) { if (!this.allowedByUserFilter(profile.id)) {
throw new ForbiddenException("UserNotWhitelisted"); throw new ForbiddenException("UserNotInUserFilter");
} }
const user = await this.usersService.createOrUpdate({ const user = await this.usersService.createOrUpdate({
@ -55,10 +55,7 @@ export class AuthService {
session.user = user; session.user = user;
await this.authSessionRepository.save(session); await this.authSessionRepository.save(session);
const [{ refreshToken }] = await Promise.all([ const { refreshToken } = await this.createRefreshToken(session);
this.createRefreshToken(session),
this.createAccessToken(session),
]);
return { session, refreshToken }; return { session, refreshToken };
} }
@ -100,23 +97,6 @@ export class AuthService {
return { accessToken: token }; return { accessToken: token };
} }
/**
* Switch to createAccessToken
* @deprecated
* @param user
*/
async createToken(user: User): Promise<{ accessToken }> {
const payload = {
sub: user.id,
name: user.displayName,
picture: user.photo,
};
const token = await this.jwtService.signAsync(payload);
return { accessToken: token };
}
async findSession(id: string): Promise<AuthSession> { async findSession(id: string): Promise<AuthSession> {
return this.authSessionRepository.findOne(id); return this.authSessionRepository.findOne(id);
} }

View file

@ -23,7 +23,7 @@ export class SpotifyAuthFilter implements ExceptionFilter {
reason = "oauth2"; reason = "oauth2";
} else if ( } else if (
exception instanceof ForbiddenException && exception instanceof ForbiddenException &&
exception.message === "UserNotWhitelisted" exception.message === "UserNotInUserFilter"
) { ) {
// User ID is not in the whitelist // User ID is not in the whitelist
reason = "whitelist"; reason = "whitelist";