Fixed authentication.

This commit is contained in:
Tom
2025-02-19 21:23:53 +00:00
parent 16f208480d
commit a764e1d441
11 changed files with 218 additions and 108 deletions

View File

@ -1,8 +1,9 @@
import { Injectable } from '@nestjs/common';
import { UserEntity } from 'src/users/users.entity';
import { UserEntity } from 'src/users/entities/users.entity';
import { UsersService } from 'src/users/users.service';
import { AuthRefreshService } from './auth.refresh.service';
import { AuthAccessService } from './auth.access.service';
import { UUID } from 'crypto';
@Injectable()
export class AuthService {
@ -26,17 +27,20 @@ export class AuthService {
async renew(
user: UserEntity,
refresh_token: string
): Promise<AuthenticationDto> {
refresh_token: string | null
): Promise<AuthenticationDto | null> {
const new_refresh_data = await this.refreshTokens.generate(user, refresh_token);
const new_refresh_token = new_refresh_data.refresh_token;
const new_refresh_exp = new_refresh_data.exp;
const access_token = await this.accessTokens.generate(user);
return {
...access_token,
refresh_token: new_refresh_token,
refresh_exp: new_refresh_exp,
refresh_token: new_refresh_data.refresh_token,
refresh_exp: new_refresh_data.exp,
}
}
async revoke(userId: UUID, refreshToken: string): Promise<boolean> {
const res = await this.refreshTokens.revoke(userId, refreshToken);
return res?.affected === 1
}
}