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

#192 feat: 로그아웃, 회원 탈퇴 시 쿠키 날린 거 앱으로 전달하는 로직 추가 #215

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/constants/postmessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const TOKEN_NULL_MESSAGE = JSON.stringify({
accessToken: null,
refreshToken: null,
});
3 changes: 2 additions & 1 deletion src/hooks/useWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const useWebView = () => {
const accessToken = Cookies.get('accessToken');
const refreshToken = Cookies.get('refreshToken');

if (accessToken != null && refreshToken != null) {
//NOTE: 사용자가 앱을 껐다가 다시 접속할 때는 브라우저 토큰 보낼 필요 없음
if (accessToken && refreshToken) {
const message = JSON.stringify({ accessToken, refreshToken });
window.ReactNativeWebView.postMessage(message);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Cookies from 'js-cookie';

import { ApiResponse, axiosRequest } from '@api/api-config';
import { TOKEN_NULL_MESSAGE } from '@constants/postmessage';

interface TokenRefreshResponse {
accessToken: string;
Expand All @@ -10,7 +11,7 @@ interface TokenRefreshResponse {
export const removeTokenAndMoveToLogin = () => {
Cookies.remove('accessToken');
Cookies.remove('refreshToken');

window.ReactNativeWebView.postMessage(TOKEN_NULL_MESSAGE);
window.location.href = '/login';
};

Expand Down
Loading