Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

week7 Assignment #5

wants to merge 8 commits into from

Conversation

hy5sun
Copy link
Owner

@hy5sun hy5sun commented May 24, 2023

  • AuthGuard 적용
  • JWT 적용
  • 로그인 & 로그아웃 구현
  • signupVerifyToken 추가
  • Cookie
  • Logger 적용


// 로그아웃
@Post('logout')
async logout(@Req() req: Request, @Res() res: Response) {
Copy link
Owner Author

@hy5sun hy5sun May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헥 req는 안 쓰이네 나중에 수정할것

Copy link

@ndaemy ndaemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 고생하셨습니다 💪

Comment on lines 57 to 62
// 쿠키 jwt 잘 읽어오는지 확인
@Get('cookie')
async getCookie(@Req() req: Request, @Res() res: Response) {
const jwt = req.cookies['auth'];
return res.send(jwt);
}
Copy link

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',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 localhost 로 하드코딩 되어있으면 안됩니다..! 나중에는 수정되어야 해요

Copy link
Owner Author

@hy5sun hy5sun May 27, 2023

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];
Copy link

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', // 만료시간
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어매 짧은거

Copy link
Owner Author

@hy5sun hy5sun May 27, 2023

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}$/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ Regex 잘 찾았구나

Copy link
Owner Author

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,
Copy link

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())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 아래 두 개 중에 어떤게 맞는거에요?
@UseGuards(AuthGuard)
@UseGuards(AuthGuard())

Copy link
Owner Author

@hy5sun hy5sun May 27, 2023

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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 더 짧게 쓰고싶으면 nanoid 같은 라이브러리도 있어요!

@kMinsAlgorithm
Copy link

퍼가요~

@hy5sun
Copy link
Owner Author

hy5sun commented May 27, 2023

헉 잠시만요 오류떴어요 다시 고쳐서 올릴게요
우와 오류 파티네요?? 지금 안 봐주셔도 됩니다.. . . . . . . 더 고치고 다시 말씀드릴게요...

@hy5sun
Copy link
Owner Author

hy5sun commented May 27, 2023

nanoid가 적용하려고 하면 오류가 나요 ㅠ
저만 이런 오류가 나는 건 아닌 것 같고.. 저랑 조금 비슷한 다른 사람 이슈 글보니까 npm으로 깔라는 사람도 있고 tsconfig.json을 수정하라는 사람도 있는데 후자는 또 다른 오류가 나고, 전자는 아예 못하겠어서 그냥... 원래 코드로 복구시킬게요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants