ref: format with prettier
This commit is contained in:
parent
ccf496a5d9
commit
a6d24cee9d
@ -5,7 +5,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"format": "prettier --write \"src/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
|
@ -27,7 +27,7 @@ async function bootstrap() {
|
||||
swaggerOptions: {
|
||||
tryItOutEnabled: true,
|
||||
persistAuthorization: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000, "0.0.0.0");
|
||||
|
@ -1,22 +1,12 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Req,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { Controller, Get, Req, Res, UseGuards } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ApiBearerAuth, ApiBody, ApiOkResponse } from "@nestjs/swagger";
|
||||
import { ApiBearerAuth, ApiOkResponse } from "@nestjs/swagger";
|
||||
|
||||
import { URLSearchParams } from "node:url";
|
||||
|
||||
import { ResfreshDTO } from "./dto/refresh.dto";
|
||||
|
||||
import { AuthService } from "./auth.service";
|
||||
import { DiscordAuthGuard } from "./guards/discord.guard";
|
||||
import { RefreshJwtAuthGuard } from "./guards/refresh.guard";
|
||||
import { AuthService } from "./auth.service";
|
||||
|
||||
@Controller("auth")
|
||||
export class AuthController {
|
||||
@ -70,10 +60,9 @@ export class AuthController {
|
||||
@Get("refresh")
|
||||
@UseGuards(RefreshJwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiBody({
|
||||
type: ResfreshDTO,
|
||||
})
|
||||
refresh(@Req() req) {
|
||||
return this.authService.accessToken(req.user);
|
||||
return {
|
||||
accessToken: this.authService.accessToken(req.user),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -10,24 +10,24 @@ export class AuthService {
|
||||
) {}
|
||||
|
||||
accessToken(user: { id: string }) {
|
||||
const payload = { id: user.id };
|
||||
return {
|
||||
accessToken: this.jwtService.sign(payload, {
|
||||
return this.jwtService.sign(
|
||||
{ id: user.id },
|
||||
{
|
||||
secret: this.configService.get<string>("JWT.secret"),
|
||||
expiresIn: this.configService.get<string>("JWT.expiresIn"),
|
||||
}),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
refreshToken(user: { id: string }) {
|
||||
const payload = { id: user.id };
|
||||
return {
|
||||
refreshToken: this.jwtService.sign(payload, {
|
||||
return this.jwtService.sign(
|
||||
{ id: user.id },
|
||||
{
|
||||
secret: this.configService.get<string>("JWT.refresh.secret"),
|
||||
expiresIn: this.configService.get<string>(
|
||||
"JWT.refresh.expiresIn",
|
||||
),
|
||||
}),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsJWT } from "class-validator";
|
||||
|
||||
export class ResfreshDTO {
|
||||
@ApiProperty()
|
||||
@IsJWT()
|
||||
refreshToken: string;
|
||||
}
|
@ -12,10 +12,7 @@ export class RolesGuard implements CanActivate {
|
||||
constructor(private readonly reflector: Reflector) {}
|
||||
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const role = this.reflector.get<string>(
|
||||
"role",
|
||||
context.getHandler(),
|
||||
);
|
||||
const role = this.reflector.get<string>("role", context.getHandler());
|
||||
if (!role) {
|
||||
return true;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export class UserEntity {
|
||||
|
||||
@Expose()
|
||||
@ApiProperty()
|
||||
role: $Enums.Role
|
||||
role: $Enums.Role;
|
||||
|
||||
constructor(partial: Partial<UserEntity>) {
|
||||
Object.assign(this, partial);
|
||||
|
@ -3,7 +3,7 @@ import { Module } from "@nestjs/common";
|
||||
import { UserService } from "./user.service";
|
||||
|
||||
import { PrismaService } from "@Modules/prisma/prisma.service";
|
||||
import { UserController } from './user.controller';
|
||||
import { UserController } from "./user.controller";
|
||||
|
||||
@Module({
|
||||
providers: [UserService, PrismaService],
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as Joi from 'joi';
|
||||
import * as Joi from "joi";
|
||||
|
||||
export const envValidation = Joi.object({
|
||||
DATABASE_URL: Joi.string().required(),
|
||||
|
Loading…
Reference in New Issue
Block a user