nestjs_auth...

This commit is contained in:
최준흠 2022-09-10 12:07:12 +09:00
parent a1be293719
commit d19cadf8ce

View File

@ -17,19 +17,19 @@ export class AuthService {
) {}
//app.controller.ts에서 @UseGuards(AuthGuard('local'))용
async validateUser(email: string, password: string): Promise<any> | null {
async validateUser(email: string, password: string): Promise<any | null> {
const user = await this.userService.fetchOne({ email: email })
if (user && user.password === password) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { password, ...result } = user
// result는 password 를 제외한 user의 모든 정보를 포함한다.
//console.log(result)
console.log(password)
return result
}
return null
}
async getTokens(user: User): Promise<any> {
getTokens(user: User) {
//console.log(user)
const access_token_payload = {
email: user.email,
@ -51,13 +51,13 @@ export class AuthService {
}
}
async login(email: string, password: string): Promise<any> | null {
async login(email: string, password: string): Promise<any | null> {
const user = await this.validateUser(email, password)
if (!user) return null
return await this.getTokens(user)
}
async register(data: UserDTO): Promise<any> | null {
async register(data: UserDTO): Promise<any | null> {
const user = await this.userService.add(data)
if (!user) return null
return await this.getTokens(user)