Skip to content

Commit

Permalink
Merge pull request #18 from LocalMingle/heeyong
Browse files Browse the repository at this point in the history
[수정] 로그인시 user 정보 프론트로 전달 (수정필요)
  • Loading branch information
HeeDragoN1123 authored Oct 17, 2023
2 parents a739ff0 + ddd03d5 commit f40f01e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class AuthController {
@Req() req: Request,
@Res({ passthrough: true }) res: Response // Response 객체 주입
): Promise<void> {
const { accessToken, refreshToken } = await this.authService.login({
const { accessToken, refreshToken, user } = await this.authService.login({
email,
password,
res,
Expand All @@ -65,6 +65,8 @@ export class AuthController {
// 리프레시 토큰을 HTTP 응답 헤더에 추가
res.header('refreshToken', refreshToken);

res.status(200).json({ user }); // 클라이언트에게 JSON 응답을 보냄

//res.cookie('refreshToken', refreshToken, { httpOnly: true, secure: false });

// 액세스 토큰을 클라이언트에게 JSON 응답으로 반환 (Response body 에 전송)
Expand Down
6 changes: 4 additions & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcrypt';
//import { IAuthServiceLogin } from './interface/auth-service.interface';
import { UsersService } from 'src/users/users.service';
import { User } from '@prisma/client';

@Injectable()
export class AuthService {
Expand All @@ -21,10 +22,11 @@ export class AuthService {
// 리팩토링 시 res 빼도 작동하는지 테스트
accessToken: string;
refreshToken: string;
user: User; // User 정보를 반환하기 위한 타입
}> {
// 1. 이메일이 일치하는 유저를 DB에서 찾기
const user = await this.usersService.findByEmail({ email });

console.log(user);
// 2. 일치하는 유저가 없으면 에러
if (!user) throw new NotFoundException('이메일이 없습니다.');

Expand All @@ -51,7 +53,7 @@ export class AuthService {
// res.header('Authorization', `Bearer ${accessToken}`);
// res.header('RefreshToken', refreshToken);

return { accessToken, refreshToken };
return { accessToken, refreshToken, user }; //리턴값
}

getAccessToken({ user, res }): string {
Expand Down

0 comments on commit f40f01e

Please sign in to comment.