Skip to content

Commit 3bc2d73

Browse files
committed
feat: WebView에 토큰 및 알림 권한 요청 메시지 전송 기능 추가
1 parent dea8d95 commit 3bc2d73

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/controllers/common/base.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { webPath } from '@router/index';
2+
import { MESSAGE_TYPES } from '../../config/webview';
23

34
const baseURL = import.meta.env.VITE_BASE_URL;
45
const Headers = { 'Content-Type': 'application/json' } as const;
@@ -72,11 +73,11 @@ const fetchAuthData = async (path: string, init: RequestInit = {}, isFormData: b
7273
window.dispatchEvent(new CustomEvent('localStorageChange', { detail: { key: 'access_token' } }));
7374
window.dispatchEvent(new CustomEvent('localStorageChange', { detail: { key: 'refresh_token' } }));
7475

75-
(window as any).ReactNativeWebView?.postMessage(JSON.stringify({ type: 'TOKEN', token: access_token }));
76-
// const token = localStorage.getItem('access_token');
77-
// if (token && window.ReactNativeWebView) {
78-
// window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'TOKEN', token }));
79-
// }
76+
// WebView에 새 토큰 전달
77+
(window as any).ReactNativeWebView?.postMessage(
78+
JSON.stringify({ type: MESSAGE_TYPES.TOKEN, token: access_token }),
79+
);
80+
8081
// 원래 요청 재시도
8182
res = await fetch(url, {
8283
method: 'GET',
@@ -104,10 +105,4 @@ const fetchAuthData = async (path: string, init: RequestInit = {}, isFormData: b
104105
return data;
105106
};
106107

107-
// function getCookie(name: string) {
108-
// const value = `; ${document.cookie}`;
109-
// const parts = value.split(`; ${name}=`);
110-
// if (parts.length === 2) return parts.pop()?.split(';').shift();
111-
// }
112-
113108
export { baseURL, Headers, wait, enableMock, fetchData, fetchAuthData };

src/hooks/useSocialAuth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ export const useSocialAuth = () => {
133133
}),
134134
);
135135
}
136+
137+
if (isWebView && (window as any).ReactNativeWebView) {
138+
(window as any).ReactNativeWebView.postMessage(
139+
JSON.stringify({
140+
type: MESSAGE_TYPES.REQUEST_NOTIFICATION_PERMISSION,
141+
token: res.access_token,
142+
}),
143+
);
144+
}
145+
136146

137147
// 저장된 return path로 이동
138148
const savedReturnPath = sessionStorage.getItem('login_return_path');

0 commit comments

Comments
 (0)