update
This commit is contained in:
@@ -10,6 +10,7 @@ import { AuthMessage, UserMessage } from '../../../common/enums/message.enum';
|
||||
import { RefreshToken } from '../../users/entities/refresh-token.entity';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { ITokenPayload } from '../interfaces/IToken-payload';
|
||||
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TokensService {
|
||||
@@ -20,10 +21,11 @@ export class TokensService {
|
||||
private readonly em: EntityManager,
|
||||
) {}
|
||||
|
||||
async generateTokens(user: User, em?: EntityManager) {
|
||||
async generateTokens(user: User, rest: Restaurant, em?: EntityManager) {
|
||||
return this.generateAccessAndRefreshToken(
|
||||
{
|
||||
id: user.id,
|
||||
restId: rest.id,
|
||||
},
|
||||
em,
|
||||
);
|
||||
@@ -33,7 +35,11 @@ export class TokensService {
|
||||
const accessExpire = this.configService.getOrThrow<number>('ACCESS_TOKEN_EXPIRE');
|
||||
const refreshExpire = this.configService.getOrThrow<number>('REFRESH_TOKEN_EXPIRE');
|
||||
|
||||
const accessToken = await this.jwtService.signAsync(payload, { expiresIn: `${accessExpire}m` });
|
||||
const tokenPayload: ITokenPayload = {
|
||||
id: payload.id,
|
||||
restId: payload.restId,
|
||||
};
|
||||
const accessToken = await this.jwtService.signAsync(tokenPayload, { expiresIn: `${accessExpire}m` });
|
||||
const refreshToken = this.generateRefreshToken();
|
||||
|
||||
await this.storeRefreshToken(payload.id, refreshToken, em);
|
||||
|
||||
Reference in New Issue
Block a user