Skip to content

Commit

Permalink
[Feat]회원탈퇴 시 로그아웃, 토큰삭제
Browse files Browse the repository at this point in the history
회원탈퇴 훅에서 로그아웃 전역변수 변동, 엑세스토큰을 로컬 스토리지에서 삭제
Issues #70
  • Loading branch information
김병현 authored and 김병현 committed Sep 16, 2023
1 parent c9c3323 commit 57bf623
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions client/src/components/Profile/memberWithdrawalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import { useDeleteMember } from '../../hooks/useDeleteMembers';


const MemberWithdrawalModal: React.FC<MemberWithdrawalModalProps> = ({ onClose }) => {

const [inputString, setInputString] = useState<string>('');
const [errorMsg, setErrorMsg] = useState<string | null>(null);
const deleteMemberMutation = useDeleteMember();


const withdrawalTitle = "StockHolm에서 탈퇴하시겠습니까?";
const inputStringLabel = "다음 문자열을 입력해주세요: Codestates";
const incorrectStringMsg = "문자열이 일치하지 않습니다!";
Expand Down
19 changes: 15 additions & 4 deletions client/src/hooks/useDeleteMembers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { useMutation } from 'react-query';
import axios from 'axios';
import { useDispatch } from 'react-redux'; // <-- 이 부분을 추가하세요.
import { setLogoutState } from '../reducer/member/loginSlice';

export function useDeleteMember() {
return useMutation(async () => {
const response = await axios.delete(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/members/`);
const dispatch = useDispatch(); // <-- useDispatch를 호출해 dispatch 함수를 가져옵니다.

return useMutation(async () => {
const response = await axios.delete(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/members`, {});

if (response.status !== 204) {
throw new Error('Failed to delete member');
}
}, {
onSuccess: () => {
alert('회원탈퇴 되었습니다!');
// 토큰 삭제
localStorage.removeItem('accessToken');

// 로그아웃 상태로 변경
dispatch(setLogoutState());

// 페이지 새로고침 (선택사항)
window.location.reload();
}
});
}
}

0 comments on commit 57bf623

Please sign in to comment.