-
Notifications
You must be signed in to change notification settings - Fork 1
Feat(Client): refreshtoken update #308
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
Changes from all commits
c80b181
2effd38
e22c160
3e0bbff
def11bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ง๊ธ 401์ฒ๋ฆฌ์ refreshํ๋ ๋ก์ง์ ์ ์์ฑ์ ํด์ฃผ์๊ธด ํ์ง๋ง ํ๊ฐ์ง ๋ฌธ์ ๊ฐ ์์ ๊ฒ ๊ฐ์์. ํ์ฌ ์๋ ๋ฐ๋ผ์ ์ด๋ฅผ
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refresh๊ฐ ์ฒ์์ด๋ผ ์ด ๋ถ๋ถ์ ์์ํ์ง ๋ชปํ๋๋ฐ ์ด์ํ์ ๊ณต๋ถํ๊ณ ์์ ํด๋ณด๊ฒ ์ต๋๋ค-! |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,7 +28,8 @@ apiRequest.interceptors.response.use( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const noAuthNeeded = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/api/v1/auth/token', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/api/v3/auth/signup', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/api/v2/auth/google', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/api/v3/auth/google', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/api/v3/auth/reissue', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isNoAuth = noAuthNeeded.some((url) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -46,10 +47,34 @@ apiRequest.interceptors.response.use( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originalRequest._retry = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // localStorage.removeItem('token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.location.href = '/onboarding?step=SOCIAL_LOGIN'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const res = await axios.post( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${import.meta.env.VITE_BASE_URL}/api/v3/auth/reissue`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withCredentials: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+56
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํด๋น |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Promise.reject(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newAccessToken = res.data.data.token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localStorage.setItem('token', newAccessToken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.postMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { type: 'SET_TOKEN', token: newAccessToken }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.location.origin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฌ์ค ์ ํฌ ํ๋ก์ ํธ๊ฐ ํ ํฐ์ extension์ด๋ client๊ฐ ์ฃผ๊ณ ๋ฐ์์ผ ํ๋ ๊ตฌ์กฐ๋ค๋ณด๋๊น,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๊ฑด ๋ค์ ์๊ฐํด๋ณด๋๊น ์ด ๋๊ฐ๋ฅผ ๋ฌถ์ด์ ์ถ์ํํ๊ธฐ๊ฐ ์กฐ๊ธ ์ ๋งคํ ๊ฑฐ ๊ฐ๊ธฐ๋ํด์. ์ ๋ฏผ๋์ ์ด๋ป๊ฒ ์๊ฐํ์๋์!??! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originalRequest.headers.Authorization = `Bearer ${newAccessToken}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return apiRequest(originalRequest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (reissueError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('ํ ํฐ ์ฌ๋ฐ๊ธ ์คํจ. ๋ค์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.', reissueError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localStorage.removeItem('token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localStorage.removeItem('refreshToken'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+72
to
+73
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.location.href = '/onboarding?step=SOCIAL_LOGIN'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Promise.reject(reissueError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ ํฐ ์ฌ๋ฐ๊ธ์ ๋จ์ผ ํ๋ก์ฐ๋ก ์ง๋ ฌํํด ์ฃผ์ธ์. ์ฌ๊ธฐ์๋ 401/403์ด ๋์์ ์ฌ๋ฌ ๊ฐ ๋ค์ด์ค๋ฉด ๊ฐ ์์ฒญ์ด ์์ ์์ ์+let refreshRequest: Promise<string> | null = null;
+
apiRequest.interceptors.response.use(
(response) => response,
async (error) => {
@@
- try {
- const res = await axios.post(
- `${import.meta.env.VITE_BASE_URL}/api/v3/auth/reissue`,
- {},
- {
- withCredentials: true,
- }
- );
-
- const newAccessToken = res.data.data.token;
+ try {
+ refreshRequest ??= axios
+ .post(
+ `${import.meta.env.VITE_BASE_URL}/api/v3/auth/reissue`,
+ {},
+ { withCredentials: true }
+ )
+ .then((res) => res.data.data.token)
+ .finally(() => {
+ refreshRequest = null;
+ });
+
+ const newAccessToken = await refreshRequest;
localStorage.setItem('token', newAccessToken);
@@
- originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
+ originalRequest.headers = {
+ ...originalRequest.headers,
+ Authorization: `Bearer ${newAccessToken}`,
+ };
return apiRequest(originalRequest);๐ Committable suggestion
Suggested change
๐งฐ Tools๐ช ast-grep (0.41.0)[warning] 59-59: Detected potential storage of sensitive information in browser localStorage. Sensitive data like email addresses, personal information, or authentication tokens should not be stored in localStorage as it's accessible to any script. (browser-storage-sensitive-data) ๐ค Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Promise.reject(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refresh Token์
localStorage์ ์ ์ฅํ์ง ์๋ ํธ์ด ์์ ํฉ๋๋ค.apps/client/src/shared/apis/setting/axiosInstance.ts์ Line 12-19๋refreshToken์ ์ ํ ์ฝ์ง ์๊ณ , Line 50-68์ ์ฌ๋ฐ๊ธ๋withCredentials์ฟ ํค๋ง ์ฌ์ฉํฉ๋๋ค. ์ง๊ธ ๋ณ๊ฒฝ์ ์ฌ์ฉ๋์ง๋ ์๋ ๊ณ ๊ฐ์น ํ ํฐ์ JS ์ ๊ทผ ๊ฐ๋ฅํ ์ ์ฅ์์ ํ ๋ฒ ๋ ๋ณต์ ํ๋ ์ ์ด๋ผ XSS ๋ ธ์ถ๋ฉด๋ง ๋ํ๋๋ค. ์ ๋ฌ/์ ์ฅ ์ฒด์ธ ์์ฒด๋ฅผ ์ ๊ฑฐํ๋ ์ชฝ์ด ์์ ํฉ๋๋ค.๐ ์ ์ ์์ ์
const handleUserLogin = ( isUser: boolean, accessToken: string | null, - refreshToken: string | null, hasJob?: boolean ) => { if (isUser) { if (accessToken) { localStorage.setItem('token', accessToken); @@ sendTokenToExtension(accessToken); } - - if (refreshToken) { - localStorage.setItem('refreshToken', refreshToken); - } if (typeof hasJob === 'boolean') { localStorage.setItem('hasJob', String(hasJob)); } navigate('/'); @@ - const { isUser, userId, email, accessToken, refreshToken, hasJob } = + const { isUser, userId, email, accessToken, hasJob } = res.data.data; @@ - handleUserLogin(isUser, accessToken, refreshToken, hasJob); + handleUserLogin(isUser, accessToken, hasJob);Also applies to: 44-46, 74-80
๐ค Prompt for AI Agents