- API NestJS + Prisma (base mep) : auth admin/employés, magasins, design de carte avec récompenses et images, comptes du personnel - Admin Vite/React : liste et fiche magasin, assistant de carte avec aperçu Apple/Google Wallet, gestion des employés - Logo MonEspacePro (Claude Design) en SVG, favicon Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
import { JwtPayload } from '../common/auth.types';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(config: ConfigService, private prisma: PrismaService) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: config.get<string>('jwt.accessSecret')!,
|
|
});
|
|
}
|
|
|
|
/** Un employé désactivé ou un magasin suspendu perd l'accès immédiatement. */
|
|
async validate(payload: JwtPayload): Promise<JwtPayload> {
|
|
if (payload.kind === 'staff') {
|
|
const staff = await this.prisma.staffUser.findUnique({
|
|
where: { id: payload.sub },
|
|
select: { active: true, store: { select: { status: true } } },
|
|
});
|
|
if (!staff?.active || staff.store.status === 'SUSPENDED' || staff.store.status === 'CLOSED') {
|
|
throw new UnauthorizedException();
|
|
}
|
|
}
|
|
return payload;
|
|
}
|
|
}
|