nestjs_auth...

This commit is contained in:
최준흠 2022-09-12 12:37:01 +09:00
parent bdb1f6d3fa
commit 80318c7009
3 changed files with 13 additions and 13 deletions

View File

@ -15,9 +15,7 @@ export class AuthController {
//결과오류시 NotFoundError: No User found라고 console log에 출력됨 //결과오류시 NotFoundError: No User found라고 console log에 출력됨
@Post('login') @Post('login')
async login(@Request() req) { async login(@Request() req) {
const response = await this.authService.login(req.user) return await this.authService.login(req.user)
console.log(response)
return response
} }
//사용자정보 AccesToken 확인용 //사용자정보 AccesToken 확인용
@ -26,12 +24,12 @@ export class AuthController {
@Get('profile') @Get('profile')
async getProfile(@Request() req) { async getProfile(@Request() req) {
//console.log(req) //console.log(req)
return await req.user return req.user
} }
//사용자 등록 //사용자 등록
@Post('register') @Post('register')
async add(@Body() data: UserDTO): Promise<User> { async add(@Body() data: UserDTO) {
return await this.authService.register(data) return await this.authService.register(data)
} }
} }

View File

@ -36,7 +36,7 @@ export class AuthService {
} }
async login(user: User) { async login(user: User) {
return this.getTokens(user) return await this.getTokens(user)
} }
async register(data: UserDTO): Promise<any | null> { async register(data: UserDTO): Promise<any | null> {
@ -76,6 +76,8 @@ export class AuthService {
} }
) )
]) ])
return { access_token: accessToken, refresh_token: refreshToken } const tokens = { access_token: accessToken, refresh_token: refreshToken }
console.log(tokens)
return tokens
} }
} }

View File

@ -18,7 +18,7 @@ export class UserService {
where?: Prisma.UserWhereInput where?: Prisma.UserWhereInput
}): Promise<number> { }): Promise<number> {
const { cursor, where } = params const { cursor, where } = params
return this.prisma.user.count({ return await this.prisma.user.count({
cursor, cursor,
where where
}) })
@ -33,7 +33,7 @@ export class UserService {
orderBy?: Prisma.UserOrderByWithRelationInput orderBy?: Prisma.UserOrderByWithRelationInput
}): Promise<User[]> { }): Promise<User[]> {
const { skip, take, cursor, where, orderBy } = params const { skip, take, cursor, where, orderBy } = params
return this.prisma.user.findMany({ return await this.prisma.user.findMany({
skip, skip,
take, take,
cursor, cursor,
@ -44,12 +44,12 @@ export class UserService {
//단일 조회 //단일 조회
async fetchOne(where: Prisma.UserWhereInput): Promise<User | null> { async fetchOne(where: Prisma.UserWhereInput): Promise<User | null> {
return this.prisma.user.findFirstOrThrow({ where: where }) return await this.prisma.user.findFirstOrThrow({ where: where })
} }
//단일 추가 //단일 추가
async add(data: Prisma.UserCreateInput): Promise<User> { async add(data: Prisma.UserCreateInput): Promise<User> {
return this.prisma.user.create({ data }) return await this.prisma.user.create({ data })
} }
//단일 수정 //단일 수정
@ -58,7 +58,7 @@ export class UserService {
data: Prisma.UserUpdateInput data: Prisma.UserUpdateInput
}): Promise<User | null> { }): Promise<User | null> {
const { where, data } = params const { where, data } = params
return this.prisma.user.update({ return await this.prisma.user.update({
data, data,
where where
}) })
@ -66,6 +66,6 @@ export class UserService {
//단일 삭제 //단일 삭제
async remove(where: Prisma.UserWhereUniqueInput): Promise<User | null> { async remove(where: Prisma.UserWhereUniqueInput): Promise<User | null> {
return this.prisma.user.delete({ where }) return await this.prisma.user.delete({ where })
} }
} }