This commit is contained in:
2026-03-10 10:47:25 +03:30
parent d07f7d3777
commit 4104bab0c6
64 changed files with 189 additions and 38637 deletions
+6 -7
View File
@@ -9,8 +9,7 @@ import dayjs from 'dayjs';
import { AuthMessage } from '../../../common/enums/message.enum';
import { RefreshToken, RefreshTokenType } from '../entities/refresh-token.entity';
import { IAdminTokenPayload, ITokenPayload } from '../interfaces/IToken-payload';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Injectable()
export class TokensService {
private readonly logger = new Logger(TokensService.name);
@@ -110,15 +109,15 @@ export class TokensService {
const isAdmin = token.type === RefreshTokenType.ADMIN;
// Verify restaurant still exists
const restaurant = await em.findOne(Restaurant, { id: restId });
if (!restaurant) {
throw new UnauthorizedException(AuthMessage.INVALID_REFRESH_TOKEN);
}
// const restaurant = await em.findOne(Restaurant, { id: restId });
// if (!restaurant) {
// throw new UnauthorizedException(AuthMessage.INVALID_REFRESH_TOKEN);
// }
try {
// Generate new tokens first (before removing old token)
// Pass the transaction EntityManager to ensure operations are within the transaction
const tokens = await this.generateAccessAndRefreshToken(ownerId, restaurant.id, isAdmin, restaurant.slug, em);
const tokens = await this.generateAccessAndRefreshToken(ownerId, "restaurant.id", isAdmin, "restaurant.slug", em);
// Remove old token only after new token is created
em.remove(token);