From 4a4e2d25688b6726f9d8ed6c69ba109c183cdf7a Mon Sep 17 00:00:00 2001 From: Yelynn Oh Date: Wed, 31 Jan 2024 14:56:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#192=20feat:=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83,=20=ED=9A=8C=EC=9B=90=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=8B=9C=20=EC=BF=A0=ED=82=A4=20=EB=82=A0=EB=A6=B0=20=EA=B1=B0?= =?UTF-8?q?=20=EC=95=B1=EC=9C=BC=EB=A1=9C=20=EC=A0=84=EB=8B=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/postmessage.ts | 4 ++++ src/hooks/useWebView.ts | 1 + src/utils/auth.ts | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/constants/postmessage.ts diff --git a/src/constants/postmessage.ts b/src/constants/postmessage.ts new file mode 100644 index 00000000..e07f3bb5 --- /dev/null +++ b/src/constants/postmessage.ts @@ -0,0 +1,4 @@ +export const TOKEN_NULL_MESSAGE = JSON.stringify({ + accessToken: null, + refreshToken: null, +}); diff --git a/src/hooks/useWebView.ts b/src/hooks/useWebView.ts index 6e9d5635..0aaf5e68 100644 --- a/src/hooks/useWebView.ts +++ b/src/hooks/useWebView.ts @@ -8,6 +8,7 @@ const useWebView = () => { const accessToken = Cookies.get('accessToken'); const refreshToken = Cookies.get('refreshToken'); + //NOTE: 사용자가 앱을 껐다가 다시 접속할 때는 브라우저 토큰 보낼 필요 없음 if (accessToken != null && refreshToken != null) { const message = JSON.stringify({ accessToken, refreshToken }); window.ReactNativeWebView.postMessage(message); diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 41051ddd..80ddfb1e 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -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; @@ -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'; }; From 2d07acaa988cc3c80e4159ff7c5a920b76b826d3 Mon Sep 17 00:00:00 2001 From: Yelynn Oh Date: Wed, 31 Jan 2024 21:40:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#192=20chore:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=ED=95=B4=20useWebView?= =?UTF-8?q?=20=ED=9B=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useWebView.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useWebView.ts b/src/hooks/useWebView.ts index 0aaf5e68..139c6110 100644 --- a/src/hooks/useWebView.ts +++ b/src/hooks/useWebView.ts @@ -9,7 +9,7 @@ const useWebView = () => { const refreshToken = Cookies.get('refreshToken'); //NOTE: 사용자가 앱을 껐다가 다시 접속할 때는 브라우저 토큰 보낼 필요 없음 - if (accessToken != null && refreshToken != null) { + if (accessToken && refreshToken) { const message = JSON.stringify({ accessToken, refreshToken }); window.ReactNativeWebView.postMessage(message); }