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

[MPDX-8386] Redirect after login #1168

Merged
merged 4 commits into from
Nov 4, 2024
Merged

[MPDX-8386] Redirect after login #1168

merged 4 commits into from
Nov 4, 2024

Conversation

canac
Copy link
Contributor

@canac canac commented Oct 31, 2024

Description

Redirect the user back to the page they were trying to go to after they successfully log in.

Looking at the redirect trace in the DevTools network tab (select preserve log, filter by Doc to see page loads, and look at the Location response header), it appears that after sign in, NextAuth, redirects back to the page that initiated the login, in our case, /login?redirect=xxx. Our getServerSideProps function on the login page notices that we have a session and a redirect URL and redirects the user one last time to their original page.

Testing

  • Go to a page that isn't a dashboard page (for example, tasks).
  • Copy the URL.
  • Sign out of MPDX and Okta.
  • Navigate to the URL you copied.
  • Ensure that when it takes you to the login page, ?redirect is set to the tasks page.
  • Ensure that you are redirected to the tasks page after logging in.

MPDX-8386

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@canac canac added the Preview Environment Add this label to create an Amplify Preview label Oct 31, 2024
@canac canac requested a review from dr-bizz October 31, 2024 19:41
@canac canac self-assigned this Oct 31, 2024
Copy link
Contributor

Preview branch generated at https://8386-login-redirect.d3dytjb8adxkk5.amplifyapp.com

Copy link
Contributor

github-actions bot commented Oct 31, 2024

Bundle sizes [mpdx-react]

Compared against 1c203d1

No significant changes found

Copy link
Contributor

@dr-bizz dr-bizz left a comment

Choose a reason for hiding this comment

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

This looks great! Should we automattically start to log users in when they are redirected to the login screen?

signOut({ redirect: true, callbackUrl: 'signOut' }).then(() => {
clearDataDogUser();
client.clearStore();
graphQLErrors?.forEach((graphQLError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing this window.location.pathname !== '/login'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Apollo client is no longer present on the login page, so it is impossible to receive GraphQL errors on the login page.

@canac
Copy link
Contributor Author

canac commented Nov 4, 2024

Should we automatically start to log users in when they are redirected to the login screen?

Sorry, but I'm not sure what you mean.

@canac
Copy link
Contributor Author

canac commented Nov 4, 2024

Should we automatically start to log users in when they are redirected to the login screen?

@dr-bizz Do you mean adjusting this useEffect to always run regardless of whether immediateSignIn is true or false? Or did you mean something else?

useEffect(() => {
  if (immediateSignIn) {
    signIn(signInAuthProviderId);
  }
}, []);

@dr-bizz
Copy link
Contributor

dr-bizz commented Nov 4, 2024

Should we automatically start to log users in when they are redirected to the login screen?

Sorry, but I'm not sure what you mean.

Sorry, I can add more context. When we redirect users from the page they were on to the login page, we shouldn't add another click to the user, we should start to log the users in as soon as they land on the login. They will need to add their login details.

Yes, It's using the immediateSignIn when users are redirected to the login screen when they are not authenticated.

@canac canac requested a review from dr-bizz November 4, 2024 19:50
@canac canac force-pushed the 8386-login-redirect branch from 25147a1 to 6626050 Compare November 4, 2024 21:05
@canac canac merged commit 975d3ae into main Nov 4, 2024
17 of 18 checks passed
@canac canac deleted the 8386-login-redirect branch November 4, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Preview Environment Add this label to create an Amplify Preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants