Fixed authentication.
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user