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

[Fe/#248] token reissuance #255

Open
wants to merge 4 commits into
base: fe/dev
Choose a base branch
from
Open

Conversation

Klomachenko
Copy link
Collaborator

@Klomachenko Klomachenko commented Feb 2, 2024

๐ŸŽซ ์—ฐ๊ด€ ํ‹ฐ์ผ“

#248
#239

๐Ÿ™ ์ž‘์—…

  • ์—ฐ๊ฒฐ๋œ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ api๋ฅผ ์ด์šฉํ•ด ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๐Ÿ’โ€โ™‚๏ธ ์–ด๋–ป๊ฒŒ?

api.interceptors.response.use(
  (response) => {
    return response;
  },
  async (error) => {
    const { config, response: { status } } = error;
    const originalRequest = config;

    if (status === 403) {
      const accessToken = localStorage.getItem('access');
      const refreshToken = localStorage.getItem('refresh');

      try {
        const { data } = await axios({
          method: 'post',
          url: '/members/token',
          data: { accessToken, refreshToken },
        });

        // ... (ํ† ํฐ ์—…๋ฐ์ดํŠธ ๋ฐ ์žฌ์‹œ๋„ ๋กœ์ง)
      } catch (error) {
        // ... (์—๋Ÿฌ ์ฒ˜๋ฆฌ ๋กœ์ง)
      }
    }
  },
);
  • api.interceptors.response.use๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‘๋‹ต์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค
  • 403 ์ƒํƒœ์ฝ”๋“œ ๋ฐœ์ƒ์‹œ ํ† ํฐ ๋งŒ๋ฃŒ๋กœ ๊ฐ„์ฃผํ•˜๊ณ , ์žฌ๋ฐœ๊ธ‰์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค
  • axios๋ฅผ์ด์šฉํ•˜์—ฌ members/token์—”๋“œํฌ์ธํŠธ๋กœ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ์š”์ฒญ์„ ๋ณด๋ƒ…๋‹ˆ๋‹ค.
  • ์žฌ๋ฐœ๊ธ‰ ์„ฑ๊ณต์‹œ ๋ฐ›์€ ์ƒˆ๋กœ์šด access, refresh ํ† ํฐ์„ ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค
  • ๊ธฐ์กด ์š”์ฒญ์˜ ํ—ค๋”๋ฅผ ์ƒˆ๋กœ์šด access ํ† ํฐ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•˜๊ณ , ๊ธฐ์กด ์š”์ฒญ์„ ์žฌ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ™ˆ PR ์ฐธ๊ณ  ์‚ฌํ•ญ

ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ๋กœ์ง ์ˆœ์„œ

  • ํด๋ผ์ด์–ธํŠธ์—์„œ ์„œ๋ฒ„๋กœ ์š”์ฒญ
  • ์„œ๋ฒ„์—์„œ 403 ์‘๋‹ต ์ˆ˜์‹ 
  • ํ† ํฐ ์žฌ๋ฐœ๊ธ‰์„ ์œ„ํ•œ ์žฌ์š”์ฒญ
  • ์ƒˆ๋กœ์šด ํ† ํฐ์„ ๋ฐ›์•„ ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์ €์žฅ
  • ๊ธฐ์กด ์š”์ฒญ์˜ ํ—ค๋”๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ์žฌ์‹œ๋„

๊ธฐ์กด ์ฝ”๋“œ์—์„œ ๋ณ€๊ฒฝ์‚ฌํ•ญ

  • ๊ธฐ์กด ์ฝ”๋“œ์— useRefreshToken.ts์—์„œ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ๋กœ์ง์ด ๋“ค์–ด๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
    • useRefreshToken์€ Hook์ธ๋ฐ, ํ•ด๋‹น Hook์€ ์ตœ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์—์„œ๋งŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค
    • ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด useMutation๋Œ€์‹ , ์ผ๋ฐ˜ apiํ˜ธ์ถœ๋กœ ๊ฐ€์ ธ์˜ค๋„๋ก axios interceptor์—์„œ ํ† ํฐ์„ ๊ทธ๋Œ€๋กœ ๋ฐ›์•„์˜ค๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • ํ˜„์žฌ ๊ณ„์ธต์ด Axios -> Api -> ReactQuery ๊ณ„์ธต์ธ๋ฐ, ํ•œ ๋‹จ๊ณ„์‹ ์˜ฌ๋ผ๊ฐ€๋Š” ๊ฑด ๊ดœ์ฐฎ์ง€๋งŒ, ํ˜„์žฌ ํ† ํฐ ์žฌ๋ฐœํ–‰์€ ReactQuery์—์„œ Axios๋กœ ๋ฐ”๋กœ ์˜ฌ๋ผ๊ฐ€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. (์ด๋Š” ๊ธฐ๋Šฅ ์ž์ฒด์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค)

header ๊ด€๋ จ

  • ํ˜„์žฌ header์— bearer accesstoken ๋งŒ ๋„ฃ์–ด์„œ ๋ณด๋‚ด์ฃผ๊ณ  ์žˆ๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค
originalRequest.headers = {
  'Content-Type': 'application/json',
  Authorization: 'Bearer ' + newAccessToken,
};
  • swagger๋ฅผ ๋ณด๋ฉด referer๊ณผ uuid๋ฅผ ๊ฐ™์ด ๋‹ด์•„์„œ ๋ณด๋‚ด์ฃผ๋ผ๊ณ  ํ•˜๋Š”๋ฐ, ํ•ด๋‹น ๋ถ€๋ถ„์€ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๋‚˜์š”?

ํ† ํฐ ๋งŒ๋ฃŒ ๊ด€๋ จ

  • ํ† ํฐ ๋งŒ๋ฃŒ๊ฐ€ ๋‚˜์•ผ ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ํ•ด๋ณผํ…๋ฐ, ์ผ๋‹จ ๊ทธ๊ฑธ ์ฒดํฌํ•ด๋ณผ ์ˆ˜ ์—†์–ด์„œ ๊ทธ๋ƒฅ 403์—๋Ÿฌ ๋ฐœ์ƒ์‹œ ์ž‘๋™ํ•˜๋Š” ์—๋Ÿฌ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด๋†“์•˜์Šต๋‹ˆ๋‹ค

๐Ÿ“ธ ์Šคํฌ๋ฆฐ์ƒท

  • ํ™•์ธ ํ•„์š”.
    • ๊ฒ€์ฆ์„ ์œ„ํ•ด ํ† ํฐ ๋งŒ๋ฃŒ์‹œ๊ฐ„๊ณผ ์—๋Ÿฌ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

๐Ÿค– ํ…Œ์ŠคํŠธ ์ฒดํฌ๋ฆฌ์ŠคํŠธ

  • ์ฒดํฌ ๋ฏธ์™„๋ฃŒ
  • ์ฒดํฌ ์™„๋ฃŒ

Related to ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ๊ธฐ๋Šฅ ๊ตฌํ˜„ #248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant