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

Refresh tokens #7

Merged
merged 11 commits into from
Nov 27, 2023
Merged

Refresh tokens #7

merged 11 commits into from
Nov 27, 2023

Conversation

tysky
Copy link
Contributor

@tysky tysky commented Nov 15, 2023

No description provided.

Comment on lines 41 to 42
this.logger.log(`Access token has been refreshed successfully at ${currentTime}`)
this.logger.log(`Refresh token has been refreshed successfully at ${currentTime}`)

Choose a reason for hiding this comment

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

в силу того, что токены обновляются всегда парой, лично я не вижу смысла выводить в консоль две строчки в таком виде и предлагаю просто писать, что токены обновлены

this.#refreshTokensByTimer({ fetchTokens, saveTokens })
}

#refreshTokensByTimer = ({ fetchTokens, saveTokens }) => {

Choose a reason for hiding this comment

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

в целом, на самом деле, этот метод токены не рефрешит, а лишь ставит макрозадачу на обновление, может так и назвать, что-то типа scheduleRefreshTokens ?

Choose a reason for hiding this comment

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

ну или даже scheduleTokensRefreshing, но это немного не так явно согласуется с оригинальным названием

Comment on lines 127 to 138
authentication = async ({ fetchTokens, saveTokens }) => {
const { accessToken } = fetchTokens()
try {
verify(accessToken)
}
catch (err) {
await this.#refresh({ fetchTokens, saveTokens, immediate: true })
return
}

this.#refresh({ fetchTokens, saveTokens, immediate: false })
}

Choose a reason for hiding this comment

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

ну лично мне кажется, логика несколько переусложенена с этим immediate, не? можно же просто сделать

Suggested change
authentication = async ({ fetchTokens, saveTokens }) => {
const { accessToken } = fetchTokens()
try {
verify(accessToken)
}
catch (err) {
await this.#refresh({ fetchTokens, saveTokens, immediate: true })
return
}
this.#refresh({ fetchTokens, saveTokens, immediate: false })
}
authentication = async ({ fetchTokens, saveTokens }) => {
const { accessToken } = fetchTokens()
try {
verify(accessToken)
}
catch (err) {
await this.#refresh({ fetchTokens, saveTokens })
return
}
this.#scheduleRefreshTokens({ fetchTokens, saveTokens })
}

Choose a reason for hiding this comment

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

лично на мой вкус так более явно прослеживается намерение, чем прыгать по методам с иммедиейтом

}
catch (err) {
await this.#refresh({ fetchTokens, saveTokens, immediate: true })
return

Choose a reason for hiding this comment

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

а почему при обычном рефреше делается ретюрн? оно же не поставит задачу на обновление, или там хитрее как-то работает, а я не уследил?

.gitignore Outdated Show resolved Hide resolved
src/client/AutherClient.js Outdated Show resolved Hide resolved
src/client/AutherClient.js Show resolved Hide resolved
src/client/AutherClient.js Outdated Show resolved Hide resolved
@tysky tysky marked this pull request as ready for review November 20, 2023 07:29
@tysky tysky merged commit 922ba7a into Cado-Labs:master Nov 27, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants