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

[#25] [#36] [Backend] As a user, I can automatically re-authenticate if my access token expires [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages #34

Open
wants to merge 14 commits into
base: feature/21-backend-login-email-password
Choose a base branch
from

Conversation

liamstevens111
Copy link
Owner

@liamstevens111 liamstevens111 commented Feb 16, 2023

What happened 👀

  • Include access_token in Authorization header on all requests
  • Request and store new acces_token using refresh token upon 401 error, if token doesn't exist then redirect to login page.
  • Create Context for the User
  • Set the user in context on successful login requests
  • Protected routes

I have some Tests for Axios Interceptors (in requestManager) but I couldn't mock the Interceptor for fetching new token using refresh in RequestManager on error response. For some reason I could not assert the storage was called with the new access token, it kept saying it wasn't called because the re-fetch for new token errors out. it's situated on line 165 in requestManager.test.ts with xit

Insight 📝

Proof Of Work 📹

Show us the implementation: screenshots, GIFs, etc.

@netlify
Copy link

netlify bot commented Feb 16, 2023

Deploy Preview for moonlit-buttercream-05cb2f ready!

Name Link
🔨 Latest commit ad66389
🔍 Latest deploy log https://app.netlify.com/sites/moonlit-buttercream-05cb2f/deploys/63f8802a524199000866112c
😎 Deploy Preview https://deploy-preview-34--moonlit-buttercream-05cb2f.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from 3bc55ab to 76a6a04 Compare February 16, 2023 05:25
@liamstevens111 liamstevens111 changed the title [#25] Initial [#25] [Backend] As a user, when I am unauthenticated I can see the Login page Feb 16, 2023
@liamstevens111 liamstevens111 self-assigned this Feb 16, 2023
@liamstevens111 liamstevens111 added the feature New feature or request label Feb 16, 2023
@liamstevens111 liamstevens111 added this to the 0.1.0 milestone Feb 16, 2023
@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from 76a6a04 to 5f1297c Compare February 16, 2023 05:31
@github-actions
Copy link

github-actions bot commented Feb 16, 2023

@github-actions github-actions bot temporarily deployed to pull request February 16, 2023 05:32 Inactive
@github-actions github-actions bot temporarily deployed to pull request February 16, 2023 06:50 Inactive
@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from 5f1297c to 1385ce6 Compare February 23, 2023 07:53
@github-actions github-actions bot temporarily deployed to pull request February 23, 2023 07:54 Inactive
@liamstevens111 liamstevens111 modified the milestones: 0.1.0, 0.2.0 Feb 23, 2023
@liamstevens111 liamstevens111 changed the base branch from feature/7-login-page to feature/36-reauthenticate-refresh-token February 24, 2023 09:15
@github-actions github-actions bot temporarily deployed to pull request February 27, 2023 02:47 Inactive
@liamstevens111 liamstevens111 changed the title [#25] [Backend] As a user, when I am unauthenticated I can see the Login page [#25] [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages #24 Feb 27, 2023
@liamstevens111 liamstevens111 changed the title [#25] [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages #24 [#25] [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages Feb 27, 2023
@liamstevens111 liamstevens111 force-pushed the feature/36-reauthenticate-refresh-token branch from c8e90ca to 6cba1d1 Compare March 7, 2023 03:45
@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from caf1305 to a1ec66d Compare March 7, 2023 03:46
@github-actions github-actions bot temporarily deployed to pull request March 7, 2023 03:48 Inactive
@liamstevens111 liamstevens111 force-pushed the feature/36-reauthenticate-refresh-token branch from 6cba1d1 to e3b555e Compare March 8, 2023 04:28
@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from a1ec66d to 06139d8 Compare March 8, 2023 04:29
@github-actions github-actions bot temporarily deployed to pull request March 8, 2023 04:31 Inactive
@liamstevens111 liamstevens111 changed the base branch from feature/36-reauthenticate-refresh-token to feature/21-backend-login-email-password March 8, 2023 04:35
@liamstevens111 liamstevens111 changed the title [#25] [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages [#25] [#36] [Backend] As a user, I can automatically re-authenticate if my access token expires [Backend] As a user, when I am unauthenticated I can see the Login page [#24] [Backend] As a user, when I am authenticated I can see my profile image at the top of all pages Mar 8, 2023
@github-actions github-actions bot temporarily deployed to pull request March 8, 2023 04:42 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 8, 2023 08:06 Inactive
@liamstevens111 liamstevens111 marked this pull request as ready for review March 8, 2023 08:13
@liamstevens111 liamstevens111 force-pushed the feature/25-login-page-when-unauthenticated branch from e1cfc27 to 949171a Compare March 20, 2023 04:55
@github-actions github-actions bot temporarily deployed to pull request March 20, 2023 05:53 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 21, 2023 05:50 Inactive
src/adapters/authAdapter.ts Outdated Show resolved Hide resolved
src/components/PrivateRoutes/index.tsx Outdated Show resolved Hide resolved
src/lib/requestManager.test.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request March 21, 2023 08:25 Inactive
};
/* eslint-enable camelcase */

return this.prototype.postRequest('oauth/token', { data: requestParams });
}

static loginWithRefreshToken(refreshToken: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we rename this function? Because user won't login after running this function but get the new access token.

Suggested change
static loginWithRefreshToken(refreshToken: string) {
static refreshAccessToken(refreshToken: string) {
static refreshUserToken(refreshToken: string) {

Copy link
Owner Author

@liamstevens111 liamstevens111 Mar 22, 2023

Choose a reason for hiding this comment

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

I named it this because the only difference between the login and refresh-token endpoint is we are sending a refresh_token instead of email/password, otherwise endpoint and response are identical.

I also deemed "login" just to be storing token in localstorage from endpoint response which is what both do.

Do you still think it's better to change it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion, the user needs to log in with their email/password first before they get a refresh token. The user can't initially log in with a refresh token. So to get a new access token, it sounds like the user refreshes the token, not re-login.
Anyway I don't have a strong opinion about this one, I am fine with both name 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

I didn't think of that - you're right there's no way to get a refresh_token without logging in first, so I will change the name 👍 @hanam1ni

Copy link
Owner Author

@liamstevens111 liamstevens111 Mar 22, 2023

Choose a reason for hiding this comment

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

As authAdapter changed to all be inside surveyAdapter in the latest survey list PR i have included it here instead:
66a6f8c

@hanam1ni fyi

src/lib/requestManager.ts Outdated Show resolved Hide resolved
src/components/PrivateRoute/index.test.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request March 22, 2023 01:56 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 22, 2023 02:02 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2.0 feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants