Skip to content

Commit

Permalink
Merge pull request #92 from LocalMingle/heeyong
Browse files Browse the repository at this point in the history
[수정] 기존 로그인 코드 수정(이전버전으로)
  • Loading branch information
HeeDragoN1123 authored Oct 24, 2023
2 parents 0376335 + 964e6cc commit b0ed533
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ export class AuthController {
@Req() req: Request,
@Res({ passthrough: true }) res: Response // Response 객체 주입
): Promise<void> {
await this.authService.login({
const { accessToken, refreshToken, userId } = await this.authService.login({
email,
password,
res,
});
res.header('accessToken', accessToken);
res.header('refreshToken', refreshToken);
res.status(200).json({ userId });
}

//-----------------------토큰 재발급-----------------------------//
Expand Down
10 changes: 7 additions & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class AuthService {
// 리팩토링 시 res 빼도 작동하는지 테스트
accessToken: string;
refreshToken: string;
userId: number;
}> {
// 1. 이메일이 일치하는 유저를 DB에서 찾기
const user = await this.usersService.findByEmail({ email });
Expand Down Expand Up @@ -56,7 +57,7 @@ export class AuthService {
},
});

return { accessToken, refreshToken };
return { accessToken, refreshToken, userId: user.userId };
}

getAccessToken({ user }): string {
Expand Down Expand Up @@ -98,6 +99,7 @@ export class AuthService {
async OAuthLogin({ req, res }): Promise<{
accessToken: string;
refreshToken: string;
// userId: number;
}> {
// 1. 회원조회
let user = await this.usersService.findByEmail({ email: req.user.email }); // user를 찾아서
Expand Down Expand Up @@ -130,12 +132,14 @@ export class AuthService {

console.log('로컬 엑세스 토큰', accessToken);
console.log('로컬 리프레시 토큰', refreshToken);

//console.log(user.userId);
// 리다이렉션
res.redirect(
`http://localhost:5173?accessToken=${encodeURIComponent(
accessToken
)}&refreshToken=${encodeURIComponent(refreshToken)}`
)}&refreshToken=${encodeURIComponent(
refreshToken
)}&userId=${encodeURIComponent(user.userId)}`
);
//&userId=${encodeURIComponent(user.userId)}
// return res.redirect('http://localhost:5500');
Expand Down

0 comments on commit b0ed533

Please sign in to comment.