Skip to content

Commit

Permalink
refactor(#10): 카카오 회원탈퇴 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoDora committed Oct 13, 2023
1 parent 13933a4 commit 539f9c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
12 changes: 2 additions & 10 deletions src/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,9 @@ export class AuthController {
async kakaoUnlink(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
const tokens = await this.tokenService.getUserTokens(userId);
let kakaoAccessToken = tokens[0].socialAccessToken;

const checkValidKakaoToken = await this.tokenService.checkValidKakaoToken(kakaoAccessToken);

if (checkValidKakaoToken === 401) {
const kakaoRefreshToken = tokens[0].socialRefreshToken;
const newKakaoToken = await this.tokenService.getNewKakaoToken(kakaoRefreshToken);
kakaoAccessToken = newKakaoToken.access_token;
}
const dbAccessToken = tokens[0].socialAccessToken;
await this.tokenService.deleteTokens(userId);
return await this.authService.kakaoUnlink(kakaoAccessToken);
return await this.authService.kakaoUnlink(accessToken, dbAccessToken);
}

@ApiOperation({ summary: '네이버 로그아웃 API', description: '네이버 로그아웃 API' })
Expand Down
29 changes: 20 additions & 9 deletions src/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,27 @@ export class AuthService {
}
}

async kakaoUnlink(accessToken: string) {
const kakaoUnlinkUrl = 'https://kapi.kakao.com/v1/user/unlink';
const kakaoUnlinkHeader = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
async kakaoUnlink(accessToken: string, dbAccessToken: string) {
try {
const checkValidKakaoToken = await this.tokenService.checkValidKakaoToken(accessToken);
if (checkValidKakaoToken === 401) {
const newKakaoToken = await this.tokenService.getNewKakaoToken(dbAccessToken);
accessToken = newKakaoToken.access_token;
}

axios.post(kakaoUnlinkUrl, {}, kakaoUnlinkHeader);
return { message: "카카오 연결 끊기가 완료되었습니다." };
const kakaoUnlinkUrl = 'https://kapi.kakao.com/v1/user/unlink';
const kakaoUnlinkHeader = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};

axios.post(kakaoUnlinkUrl, {}, kakaoUnlinkHeader);
return { message: "카카오 연결 끊기가 완료되었습니다." };
} catch (error) {
console.log(error);
throw new HttpException('알 수 없는 오류가 발생했습니다.', HttpStatus.INTERNAL_SERVER_ERROR)
}
}

async naverUnlink(accessToken: string) {
Expand Down

0 comments on commit 539f9c9

Please sign in to comment.