feat: Organization services
This commit is contained in:
@@ -15,8 +15,10 @@ import {
|
||||
} from './dto';
|
||||
import { Response } from 'express';
|
||||
import { DataResponse } from 'common/http';
|
||||
import { Public } from './decorators';
|
||||
|
||||
@Controller('auth')
|
||||
@Public()
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ import { RequestContextModule } from 'core/als/request-context.module';
|
||||
AuthService,
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useFactory: () => AuthGuard,
|
||||
inject: [Reflector],
|
||||
useClass: AuthGuard,
|
||||
},
|
||||
],
|
||||
controllers: [AuthController],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { RequestContextService } from 'core/als/request-context.service';
|
||||
@@ -10,6 +11,7 @@ import { Request } from 'express';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { PUBLIC_KEY } from 'common/keys';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly reflector: Reflector,
|
||||
@@ -30,7 +32,9 @@ export class AuthGuard implements CanActivate {
|
||||
if (!token) throw new UnauthorizedException();
|
||||
|
||||
try {
|
||||
const payload: JwtPayload = await this.jwtService.verifyAsync(token);
|
||||
const payload: JwtPayload = await this.jwtService.verifyAsync(token, {
|
||||
secret: 'demo',
|
||||
});
|
||||
this.requestContext.set('user', payload);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user