Skip to content

Conversation

@tristanjung1006
Copy link
Contributor

๐Ÿ“์ž‘์—… ๋‚ด์šฉ

TokenManager๋กœ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰, ๊ฐ์ข… ๊ธฐ๋Šฅ ๋ฒ„๊ทธ ์ˆ˜์ •

๐Ÿ’ฌ๋ฆฌ๋ทฐ ์š”๊ตฌ์‚ฌํ•ญ

API ํ˜ธ์ถœ ํ›„ response๊ฐ€ ์‹คํŒจํ•  ๊ฒฝ์šฐ(401) ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฝ์ž…ํ•ด์„œ ๋งŒ๋ฃŒ๋œ ํ† ํฐ์„ ๊ฐฑ์‹ ํ•˜๊ณ  ์žฌํ˜ธ์ถœํ•˜๋ฉด ๋˜๊ณ  ๊ธฐ์กด ViewModel ์ƒ์„ฑ์ž์— tokenManager๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

tokenManager.refreshToken(
    onSuccess = { fetchNotices() },
    onFailure = { Timber.e("Failed to refresh token and get notices") }
)
class NoticeViewModel(
    private val repository: NoticeRepository,
    private val tokenManager: TokenManager
) : ViewModel() {

๋กœ๊ทธ์บฃ์— ์ฐํžŒ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰๋˜๋Š” ๊ณผ์ •์„ ์ฒจ๋ถ€ํ–ˆ์œผ๋‹ˆ ์ฐธ๊ณ ๋ฐ”๋ž๋‹ˆ๋‹ค.

mypageViewModel
homeViewModel

ํ˜„์žฌ ๋ช‡๋ช‡ domain ๋กœ์ง์˜ repository์— Retrofit ๊ฐ์ฒด(RetrofitInstance)๋ฅผ ๋งŒ๋“ค์–ด์„œ tokenStorage๋กœ๋ถ€ํ„ฐ ์ง์ ‘ access token์„ ๋ฐ›์•„์˜ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ฒ˜์Œ ๋กœ๊ทธ์ธ์‹œ AuthNetworkModule์—์„œ Bearer $access token ํ˜•์‹์œผ๋กœ ์ž๋™ ์ €์žฅํ•˜๊ณ  ์žˆ์œผ๋‹ˆ ํ•ด๋‹น ๋ชจ๋“ˆ ์‚ฌ์šฉ์„ ๊ถŒ์žฅ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

@tristanjung1006 tristanjung1006 added ๐Ÿ› fix ๋ฒ„๊ทธ ๋ฐ ๊ธฐํƒ€ ์˜ค๋ฅ˜ ์ˆ˜์ • โ™ป๏ธ refactor ์ฝ”๋“œ ๊ฐœ์„  labels Nov 16, 2024
@tristanjung1006 tristanjung1006 self-assigned this Nov 16, 2024
Copy link
Contributor

@jeong724 jeong724 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆ˜๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค~! ํ˜น์‹œ ๋‚˜๋„ ์ฝ”๋“œ ์ˆ˜์ •ํ•  ๋ถ€๋ถ„์ด ์žˆ์„๊นŒ??

@tristanjung1006
Copy link
Contributor Author

์ˆ˜๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค~! ํ˜น์‹œ ๋‚˜๋„ ์ฝ”๋“œ ์ˆ˜์ •ํ•  ๋ถ€๋ถ„์ด ์žˆ์„๊นŒ??

๋„ˆ๋ž‘ ๋‚˜๋ž‘ Retrofit ๊ฐ์ฒด ๋‹ค๋ฃจ๋Š” ๋ถ€๋ถ„์ด ๋‹ฌ๋ผ์„œ ๋””์Šค์ฝ”๋“œ๋กœ ์ง์ ‘ ์•Œ๋ ค์ค˜์•ผํ•  ๊ฒƒ ๊ฐ™์œผ

@tristanjung1006 tristanjung1006 merged commit da6704d into master Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

๐Ÿ› fix ๋ฒ„๊ทธ ๋ฐ ๊ธฐํƒ€ ์˜ค๋ฅ˜ ์ˆ˜์ • โ™ป๏ธ refactor ์ฝ”๋“œ ๊ฐœ์„ 

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants