16 lines
557 B
TypeScript
16 lines
557 B
TypeScript
import { CanActivate, ExecutionContext, ForbiddenException, Injectable } from '@nestjs/common';
|
|
import type { AuthUser } from './jwt-auth.guard';
|
|
|
|
/** Shop business APIs require JWT claim storeId (after select-store). */
|
|
@Injectable()
|
|
export class ShopStoreGuard implements CanActivate {
|
|
canActivate(context: ExecutionContext): boolean {
|
|
const req = context.switchToHttp().getRequest();
|
|
const user = req.user as AuthUser | undefined;
|
|
if (!user?.storeId) {
|
|
throw new ForbiddenException('请先选择门店');
|
|
}
|
|
return true;
|
|
}
|
|
}
|