-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
|
||
@Injectable() | ||
export class NaverAuthGuard extends AuthGuard('naver') { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
handleRequest<TUser = any>( | ||
err: any, | ||
user: any, | ||
info: any, | ||
context: ExecutionContext, | ||
status?: any, | ||
): TUser { | ||
//에러가 존재하면 에러 처리로 넘긴다. | ||
if (err || !user) { | ||
throw err; | ||
} | ||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { Strategy } from 'passport-naver-v2'; | ||
import { AuthService } from '../auth.service'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { | ||
ENV_NAVER_CALLBACK_URL_KEY, | ||
ENV_NAVER_CLIENT_ID_KEY, | ||
ENV_NAVER_CLIENT_SECRET_KEY, | ||
} from '../../common/const/env-keys.const'; | ||
|
||
@Injectable() | ||
export class JwtNaverStrategy extends PassportStrategy(Strategy, 'naver') { | ||
constructor( | ||
private authService: AuthService, | ||
private jwtService: JwtService, | ||
private readonly configService: ConfigService, | ||
) { | ||
super({ | ||
clientID: configService.get<string>(ENV_NAVER_CLIENT_ID_KEY), | ||
clientSecret: configService.get<string>(ENV_NAVER_CLIENT_SECRET_KEY), | ||
callbackURL: configService.get<string>(ENV_NAVER_CALLBACK_URL_KEY), | ||
}); | ||
} | ||
|
||
async validate( | ||
accessToken: string, | ||
refreshToken: string, | ||
profile: any, | ||
): Promise<any> { | ||
console.log(profile); | ||
const id = profile.id; | ||
const email = profile.email; | ||
const name = profile.name; | ||
const user = { | ||
id, | ||
email, | ||
name, | ||
}; | ||
|
||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters