-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
week7 Assignment #5
base: main
Are you sure you want to change the base?
Conversation
hy5sun
commented
May 24, 2023
- AuthGuard 적용
- JWT 적용
- 로그인 & 로그아웃 구현
- signupVerifyToken 추가
- Cookie
- Logger 적용
|
||
// 로그아웃 | ||
@Post('logout') | ||
async logout(@Req() req: Request, @Res() res: Response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헥 req는 안 쓰이네 나중에 수정할것
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아주 고생하셨습니다 💪
// 쿠키 jwt 잘 읽어오는지 확인 | ||
@Get('cookie') | ||
async getCookie(@Req() req: Request, @Res() res: Response) { | ||
const jwt = req.cookies['auth']; | ||
return res.send(jwt); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 나중에는 없애주셔야 합니다!
async logout() { | ||
return { | ||
token: '', | ||
domain: 'localhost', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 localhost 로 하드코딩 되어있으면 안됩니다..! 나중에는 수정되어야 해요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 이거 그럼 env 파일에 있는 DB_PORT 사용하면 될까요 -> 아니래요
여기에다가는 프엔에서 띄워주는 주소를 써야하는거라 하드코딩을 하면 안됨.
|
||
// 얻은 정보를 내부 규칙으로 평가 | ||
private validateRequest(request: any) { | ||
const jwtString = request.headers.authorization.split('Bearer ')[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 좀 더 이쁜 코드도 있어요!
참고우
const payload = { loginDto }; | ||
|
||
return jwt.sign(payload, this.config.jwtSecret, { | ||
expiresIn: '1d', // 만료시간 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어매 짧은거
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅠㅠ
refreshToken도 함께 쓸거면 하루에서 일주일 정도 되고, accessToken만 사용하면 상의해야함
userId: string; | ||
|
||
@IsString() | ||
@Matches(/^[A-Za-z\d!@#$%^7*()]{8, 30}$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ Regex 잘 찾았구나
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
교재에 잇었습니다 하하
import { registerAs } from '@nestjs/config'; | ||
|
||
export default registerAs('auth', () => ({ | ||
jwtSecret: process.env.JWT_SECRET, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
import { UserService } from './user.service'; | ||
|
||
@Controller('users') | ||
export class UserController { | ||
constructor(private readonly userService: UserService) {} | ||
|
||
@UseGuards(AuthGuard()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 아래 두 개 중에 어떤게 맞는거에요?
@UseGuards(AuthGuard)
@UseGuards(AuthGuard())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전자네요....^^.....................
@@ -23,6 +24,7 @@ export class UserService { | |||
user.email = createUserDto.email; | |||
user.password = createUserDto.password; | |||
user.userId = createUserDto.userId; | |||
user.signupVerifyToken = uuid.v1(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 더 짧게 쓰고싶으면 nanoid 같은 라이브러리도 있어요!
퍼가요~ |
헉 잠시만요 오류떴어요 다시 고쳐서 올릴게요 |
nanoid가 적용하려고 하면 오류가 나요 ㅠ |