ref: just add another test route
This commit is contained in:
parent
8245f4ddfc
commit
d9cc0db0d2
15
src/app.controller.ts
Normal file
15
src/app.controller.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Controller, Get, UseGuards } from "@nestjs/common";
|
||||
import { ApiBearerAuth } from "@nestjs/swagger";
|
||||
import { JwtAuthGuard } from "./modules/auth/guards/jwt.guard";
|
||||
|
||||
@Controller()
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class AppController {
|
||||
@Get("ping")
|
||||
pong() {
|
||||
return {
|
||||
message: "pong",
|
||||
};
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import { envValidation } from "@Validations/env.validation";
|
||||
import { AuthModule } from "@Modules/auth/auth.module";
|
||||
import { UserModule } from "@Modules/user/user.module";
|
||||
import { PrismaModule } from "nestjs-prisma";
|
||||
import { AppController } from "./app.controller";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -31,5 +32,6 @@ import { PrismaModule } from "nestjs-prisma";
|
||||
UserModule,
|
||||
AuthModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
3
src/interfaces/jwtPayload.ts
Normal file
3
src/interfaces/jwtPayload.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface JwtPayload {
|
||||
id: string;
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import { JwtPayload } from "@/interfaces/jwtPayload";
|
||||
import { UserService } from "@Modules/user/user.service";
|
||||
import { Injectable, UnauthorizedException } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
import { User } from "@prisma/client";
|
||||
import { Strategy, ExtractJwt } from "passport-jwt";
|
||||
import { UserService } from "@Modules/user/user.service";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ExtractJwt, Strategy } from "passport-jwt";
|
||||
|
||||
@Injectable()
|
||||
export class JWTStrategy extends PassportStrategy(Strategy, "jwt") {
|
||||
@ -18,7 +19,7 @@ export class JWTStrategy extends PassportStrategy(Strategy, "jwt") {
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any): Promise<User> {
|
||||
async validate(payload: JwtPayload): Promise<User> {
|
||||
const user = await this.userService.findById(payload.id);
|
||||
|
||||
if (!user) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { JwtPayload } from "@/interfaces/jwtPayload";
|
||||
import { UserService } from "@Modules/user/user.service";
|
||||
import { Injectable, UnauthorizedException } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
import { User } from "@prisma/client";
|
||||
import { Strategy, ExtractJwt } from "passport-jwt";
|
||||
import { UserService } from "@Modules/user/user.service";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ExtractJwt, Strategy } from "passport-jwt";
|
||||
|
||||
@Injectable()
|
||||
export class RefreshJWTStrategy extends PassportStrategy(Strategy, "refresh") {
|
||||
@ -18,7 +19,7 @@ export class RefreshJWTStrategy extends PassportStrategy(Strategy, "refresh") {
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any): Promise<User> {
|
||||
async validate(payload: JwtPayload): Promise<User> {
|
||||
const user = await this.userService.findById(payload.id);
|
||||
|
||||
if (!user) {
|
||||
|
@ -25,7 +25,7 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string) {
|
||||
async findById(id: string = null) {
|
||||
return await this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user