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

๐Ÿ› [Fix] jwtError ๋ฒ„๊ทธ ์ˆ˜์ • #94

Closed
5 tasks done
Eunjin3395 opened this issue Oct 6, 2024 · 0 comments ยท Fixed by #107
Closed
5 tasks done

๐Ÿ› [Fix] jwtError ๋ฒ„๊ทธ ์ˆ˜์ • #94

Eunjin3395 opened this issue Oct 6, 2024 · 0 comments ยท Fixed by #107
Assignees

Comments

@Eunjin3395
Copy link
Member

Eunjin3395 commented Oct 6, 2024

๐Ÿž ๋ฒ„๊ทธ/์—๋Ÿฌ ๊ฐœ์š”

jwtError ๋ฒ„๊ทธ ์ˆ˜์ •

๐Ÿ“ ๋ฒ„๊ทธ/์—๋Ÿฌ ์„ค๋ช…

๋ฌธ์ œ ์ƒํ™ฉ

access token์ด ํ˜„์žฌ๋Š” ์ฒ˜์Œ ์†Œ์ผ“ connection์ด ์ƒ๊ฒผ์„ ๋•Œ, ์„œ๋ฒ„์—์„œ socket.token์œผ๋กœ ํ•ด๋‹น ์†Œ์ผ“์˜ token์„ ์ €์žฅํ•ด๋†“๋„๋ก ๋˜์–ด ์žˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ ์ €์žฅํ•œ ํ† ํฐ์ด ์‹œ๊ฐ„์ด ์ง€๋‚˜์„œ ๋งŒ๋ฃŒ๋˜๋ฉด, ์ด๋ฅผ ๊ฐฑ์‹ ํ•˜๋Š” ๊ณผ์ •์ด ์—†๋‹ค. ํ”„๋ก ํŠธ์—์„œ๋Š” ํ† ํฐ ๋งŒ๋ฃŒ์‹œ refresh token์œผ๋กœ ์žฌ๋ฐœ๊ธ‰์„ ๋ฐ›์•„์„œ token์„ ๊ฐฑ์‹ ํ•˜์ง€๋งŒ, ๊ทธ ๊ฐฑ์‹ ํ•œ token์ด ์„œ๋ฒ„ socket ๊ฐ์ฒด์—๋Š” ๋ฐ˜์˜๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค. ๊ทธ๋ž˜์„œ ์†Œ์ผ“ 3000 ์„œ๋ฒ„ -> 8080์„œ๋ฒ„๋กœ api ์š”์ฒญ์„ ํ•  ๋•Œ(์ฑ„ํŒ… ๋ฉ”์‹œ์ง€ ์ €์žฅ, ๋งค์นญ ๊ธฐ๋ก db ์ €์žฅ ๋“ฑ๋“ฑ) ๋งค๋ฒˆ jwt ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ์•ˆ

ํ”„๋ก ํŠธ->3000์„œ๋ฒ„๋กœ event emitํ•œ ์ดํ›„, 3000์„œ๋ฒ„์—์„œ 8080์„œ๋ฒ„๋กœ api ์š”์ฒญํ–ˆ๋Š”๋ฐ ์‘๋‹ต์ด jwt ์—๋Ÿฌ๊ฐ€ ๋‚œ ๊ฒฝ์šฐ
ํ”„๋ก ํŠธ์—๊ฒŒ jwtError๋ฅผ emitํ•˜๊ฒŒ ๋˜์–ด ์žˆ๋‹ค. (์ง€๊ธˆ์€ ๊ทธ๋ƒฅ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋งŒ ๋ณด๋‚ด๊ฒŒ ๋˜์–ด ์žˆ๋‹ค.)
์ด ๋•Œ 3000์„œ๋ฒ„๊ฐ€ ๊ฐ–๊ณ  ์žˆ๋˜ socket.token์„ jwtError์— ๊ฐ™์ด ๋‹ด์•„์„œ ๋ณด๋‚ด์ž
๊ทธ๋ฆฌ๊ณ  ํ”„๋ก ํŠธ->3000์„œ๋ฒ„๋กœ emitํ•œ event๊ฐ€ ๋ญ”์ง€ ๊ทธ event ์ด๋ฆ„๊ณผ, event์— ๋‹ด์•„ ๋ณด๋‚ธ data ์ „๋ถ€๋ฅผ jwtError์— ๊ฐ™์ด ๋‹ด์•„์„œ ๋ณด๋‚ด์ž

๊ทธ๋Ÿผ ํ”„๋ก ํŠธ์—์„œ๋Š” ์–ด๋–ค event๋ฅผ emitํ–ˆ๋Š”๋ฐ, ๊ทธ์— ๋Œ€ํ•œ ์‘๋‹ต ์ด๋ฒคํŠธ๋กœ jwtError๋ฅผ ๋ฐ›๊ฒŒ ๋œ๋‹ค. ์ด๋•Œ, data์—๋Š” error-code, token, event-name, event-data๊ฐ€ ๋“ค์–ด์žˆ๋‹ค.
์—ฌ๊ธฐ์„œ ๋ฐ›์€ token๊ณผ, ํ”„๋ก ํŠธ ์ž์‹ ์ด ๊ฐ–๊ณ  ์žˆ๋˜ token์„ ๋น„๊ตํ•ด์„œ ์„œ๋กœ ๋‹ค๋ฅด๋ฉด ์„œ๋ฒ„๊ฐ€ ์ €์žฅํ•˜๊ณ  ์žˆ๋˜ ํ† ํฐ์ด ์˜›๋‚  ๋ฒ„์ „ ํ† ํฐ์ธ ๊ฒƒ์ด๋‹ค.
jwtError ์ด๋ฒคํŠธ๋กœ ๋ฐ›์€ event-name์œผ๋กœ ๋‹ค์‹œ ์ด๋ฒคํŠธ๋ฅผ emitํ•˜๋Š”๋ฐ, ํ”„๋ก ํŠธ ์ž์‹ ์ด ๊ฐ–๊ณ  ์žˆ๋˜ token์„ ๋‹ด๊ณ , jwtError ์ด๋ฒคํŠธ๋กœ ๋ฐ›์€ event-data๋ฅผ ๋‹ด์•„์„œ emitํ•œ๋‹ค.

๊ทธ๋Ÿผ ์„œ๋ฒ„์—์„œ๋Š” ํ•ด๋‹น event๋ฅผ ๋‹ค์‹œ listenํ•˜๊ฒŒ ๋˜๊ณ , ์ด๋•Œ์—๋Š” token ๊ฐ’์ด ํฌํ•จ๋˜์–ด ๋“ค์–ด์˜ฌ ๊ฒƒ์ด๋‹ค. event์— token ๊ฐ’์ด ํฌํ•จ๋˜์–ด ์žˆ์„ ๋•Œ, ์›๋ž˜ ๊ฐ–๊ณ  ์žˆ๋˜ socket.token ๊ฐ’์„ event์—์„œ ๋ฐ›์€ token ๊ฐ’์œผ๋กœ ๊ฐฑ์‹ ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์ดํ›„ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์•ก์…˜์„ ํ•œ๋‹ค.

โœ… Resolve Todo

  • jwtError emitter ์ˆ˜์ •
  • connection ์ƒ์„ฑ ์‹œ์ ์—์„œ jwt ๋งŒ๋ฃŒ ์‹œ, ๋ณ„๋„์˜ event ๋ฐœ์ƒ์‹œํ‚ค๊ธฐ
  • connection-jwt-error event listener ์ถ”๊ฐ€: ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›์€ ํ›„ ์†Œ์ผ“ ์—ฐ๊ฒฐ ์žฌ์š”์ฒญํ•˜๊ธฐ
  • ํ”„๋ก ํŠธ์— jwt-error ๊ณตํ†ต listener ์ถ”๊ฐ€
  • 3000์„œ๋ฒ„์— ๊ณตํ†ต event listener ์ถ”๊ฐ€: event data์— token ๊ฐ’ ์žˆ๋Š” ๊ฒฝ์šฐ

๐Ÿ“š Remarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant