initial: standalone repo from monorepo split
This commit is contained in:
22
src/portal/portal-jwt.strategy.ts
Normal file
22
src/portal/portal-jwt.strategy.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
|
||||
@Injectable()
|
||||
export class PortalJwtStrategy extends PassportStrategy(Strategy, 'portal-jwt') {
|
||||
constructor(config: ConfigService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: config.get<string>('JWT_SECRET') || 'fallback',
|
||||
});
|
||||
}
|
||||
|
||||
validate(payload: any) {
|
||||
if (payload.type !== 'portal') {
|
||||
throw new UnauthorizedException('Invalid token type');
|
||||
}
|
||||
return { sub: payload.sub, tenantId: payload.tenantId, type: 'portal' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user