nestjs_auth ini...
This commit is contained in:
parent
881d4dee74
commit
4cd14dbb6d
@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { PassportModule } from '@nestjs/passport'
|
import { PassportModule } from '@nestjs/passport'
|
||||||
import { UsersModule } from 'src/user/user.module'
|
|
||||||
import { AuthService } from './auth.service'
|
import { AuthService } from './auth.service'
|
||||||
import { JwtModule } from '@nestjs/jwt'
|
import { JwtModule } from '@nestjs/jwt'
|
||||||
import { jwtConstants } from './guards/constants'
|
import { jwtConstants } from './guards/constants'
|
||||||
import { AuthController } from './auth.controller'
|
import { AuthController } from './auth.controller'
|
||||||
import { LocalStrategy } from './guards/local.strategy'
|
import { LocalStrategy } from './guards/local.strategy'
|
||||||
import { JwtStrategy } from './guards/jwt.strategy'
|
import { JwtStrategy } from './guards/jwt.strategy'
|
||||||
|
import { UsersModule } from '../user/user.module'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -20,8 +20,8 @@ import { JwtStrategy } from './guards/jwt.strategy'
|
|||||||
signOptions: { expiresIn: jwtConstants.expiresIn }
|
signOptions: { expiresIn: jwtConstants.expiresIn }
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
controllers: [AuthController],
|
||||||
providers: [AuthService, LocalStrategy, JwtStrategy],
|
providers: [AuthService, LocalStrategy, JwtStrategy],
|
||||||
exports: [AuthService],
|
exports: [AuthService]
|
||||||
controllers: [AuthController]
|
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AuthModule {}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { UserService } from 'src/user/user.service'
|
|
||||||
import { JwtService } from '@nestjs/jwt'
|
import { JwtService } from '@nestjs/jwt'
|
||||||
|
import { UserService } from '../user/user.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Strategy } from 'passport-local'
|
import { Strategy } from 'passport-local'
|
||||||
import { PassportStrategy } from '@nestjs/passport'
|
import { PassportStrategy } from '@nestjs/passport'
|
||||||
import { Injectable, UnauthorizedException } from '@nestjs/common'
|
import { Injectable, UnauthorizedException } from '@nestjs/common'
|
||||||
import { AuthService } from 'src/auth/auth.service'
|
import { AuthService } from '../auth.service'
|
||||||
import { env } from 'process'
|
import { env } from 'process'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
@ -12,10 +12,10 @@ import {
|
|||||||
import { User } from '@prisma/client'
|
import { User } from '@prisma/client'
|
||||||
import { UserDTO } from './dtos/user.dto'
|
import { UserDTO } from './dtos/user.dto'
|
||||||
import { UserService } from './user.service'
|
import { UserService } from './user.service'
|
||||||
import { HasRoles } from 'src/auth/decorators/has-roles.decorator'
|
import { HasRoles } from '../auth/decorators/has-roles.decorator'
|
||||||
import { JwtAuthGuard } from 'src/auth/guards/jwt.authguard'
|
import { JwtAuthGuard } from '../auth/guards/jwt.authguard'
|
||||||
import { Role } from 'src/auth/guards/role.enum'
|
import { Role } from '../auth/guards/role.enum'
|
||||||
import { RolesGuard } from 'src/auth/guards/roles.guard'
|
import { RolesGuard } from '../auth/guards/roles.guard'
|
||||||
|
|
||||||
@Controller('user')
|
@Controller('user')
|
||||||
export class UserController {
|
export class UserController {
|
||||||
@ -130,7 +130,7 @@ export class UserController {
|
|||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async fetchOne(@Param('id') id: number): Promise<User | undefined> {
|
async fetchOne(@Param('id') id: number): Promise<User | undefined> {
|
||||||
return this.userService.fetchOne(id)
|
return await this.userService.fetchOne({ id: Number(id) })
|
||||||
}
|
}
|
||||||
|
|
||||||
// @HasRoles(Role.USER)
|
// @HasRoles(Role.USER)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { PrismaService } from 'src/prisma.service'
|
import { PrismaService } from '../prisma.service'
|
||||||
import { UserService } from './user.service'
|
import { UserService } from './user.service'
|
||||||
import { UserController } from './user.controller'
|
import { UserController } from './user.controller'
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { Prisma, User } from '@prisma/client'
|
import { Prisma, User } from '@prisma/client'
|
||||||
import { PrismaService } from 'src/prisma.service'
|
import { PrismaService } from '../prisma.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user