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

feat: improve token handling and validation #690

Merged
merged 15 commits into from
Jun 13, 2020

Conversation

JoaoPedroAS51
Copy link
Collaborator

@JoaoPedroAS51 JoaoPedroAS51 commented May 20, 2020

Initialize Token and Refresh Token instances inside schemes. Both classes now use scheme options instead of $auth. Also move token and refresh token prefixes to scheme DEFAULTS.

Improve check method to also check tokens status, deprecating _checkStatus. Return object with token and refresh token expired status.

{
  valid: boolean,
  tokenExpired: boolean,
  refreshTokenExpired: boolean,
  isRefreshable: boolean
}

Note: valid is the only required property.

Alias HTTPRequest to AxiosRequestConfig and HTTPResponse to AxiosResponse.

RequestHandler class now use scheme options and methods instead of $auth.

Initialize Token and Refresh Token instances inside schemes. Both classes now use scheme options instead of `$auth`. Also move token and refresh token prefixes to scheme `DEFAULTS`.

Improve `check` method to also check tokens status, deprecating `_checkStatus`. Accept callbacks for token and refresh token expired status.

Use types `AxiosRequestConfig` and `AxiosResponse` instead of `HTTPRequest` and `HTTPResponse`.

RequestHandler class now use scheme options and methods instead of `$auth`.
@JoaoPedroAS51 JoaoPedroAS51 requested a review from pi0 May 20, 2020 04:20
@DraftProducts
Copy link
Contributor

Nice work

@JoaoPedroAS51
Copy link
Collaborator Author

Thanks 😄

# Conflicts:
#	src/inc/request-handler.ts
@DraftProducts
Copy link
Contributor

Have you defined the date of the V5 release ?

@JoaoPedroAS51
Copy link
Collaborator Author

Not yet. We want to make more improvements and refactors before release v5 :)

@DraftProducts
Copy link
Contributor

You should maybe add a todo list to the README of the project, in this way interested developers could make their contribution 😝

I would be interested myself 🙃

@JoaoPedroAS51
Copy link
Collaborator Author

Actually we have a board, but we need to add some more things to it.
https://github.com/nuxt-community/auth-module/projects/3

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Awesome stuff 💚

src/core/auth.ts Outdated Show resolved Hide resolved
src/inc/request-handler.ts Outdated Show resolved Hide resolved
src/schemes/local.ts Outdated Show resolved Hide resolved
constructor (auth: Auth) {
this.$auth = auth
constructor (scheme: Scheme, storage: Storage) {
this.scheme = scheme
Copy link
Member

Choose a reason for hiding this comment

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

However we call scheme instance strategy, i like your idea for simplification. Maybe can always call it scheme 👍

src/schemes/local.ts Outdated Show resolved Hide resolved
# Conflicts:
#	src/inc/request-handler.ts
#	src/schemes/local.ts
#	src/schemes/oauth2.ts
#	src/schemes/refresh.ts
Improve `check` to return object with token and refresh token expired status instead of accepting callbacks.

Object structure:
```
{
  valid: boolean,
  tokenExpired: boolean,
  refreshTokenExpired: boolean,
  isRefreshable: boolean
}
```
`valid` is the only required property.
# Conflicts:
#	src/schemes/refresh.ts
Alias `HTTPRequest` to `AxiosRequestConfig` and `HTTPResponse` to `AxiosResponse`
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