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

enh(#861): Redirect back to requested page after authentication #870

Conversation

andychukse
Copy link
Contributor

@andychukse andychukse commented Aug 19, 2024

πŸ”— Linked issue

#861

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Add functionality redirect user back to requested page after authentication
Added a redirect query parameter to auth middleware navigateTo when a guest visits authenicated page.
This will help users redirect back to previous page after sign in.
Currently when guest tries to access a protected page they are redirected to /login page and after login they are redirect to default callbackUrl unless they specify callbackUrl in the signIn function.

This feature will help automatically redirect a user back to the page they requested after login. For example, if they requested to access '/profile' and they are redirected to login page, after successful login, they will be redirected back to '/profile'. They can also override this by providing a callbackUrl in the signIn function as it is currently

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

@andychukse andychukse changed the title Enh/861 redirect back to requested page after authentication enh(#861): Redirect back to requested page after authentication Aug 19, 2024
@YarikSWT
Copy link

YarikSWT commented Sep 3, 2024

Really looking forward to this feature

@andychukse andychukse force-pushed the enh/861-redirect-back-to-requested-page-after-authentication branch from d84b51f to f3ccf91 Compare September 10, 2024 14:15
Copy link

pkg-pr-new bot commented Sep 12, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@sidebase/nuxt-auth@870

commit: 2372149

Copy link
Member

@zoey-kaiser zoey-kaiser left a comment

Choose a reason for hiding this comment

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

Love this feature! Thank you so much for your PR ❀️

One suggestion I would have is to respect the addDefaultCallbackUrl option inside the middleware and only add the callback URL to the redirect if it is enabled!

This should be a pretty straight forward adjustments, where you check if globalAppMiddleware.addDefaultCallbackUrl is set before adding query.redirect to the navigateTo call!

zoey-kaiser
zoey-kaiser previously approved these changes Sep 18, 2024
Copy link
Member

@zoey-kaiser zoey-kaiser left a comment

Choose a reason for hiding this comment

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

Functionally approved πŸ₯³

@phoenix-ru, please do a code review 😊

Copy link
Collaborator

@phoenix-ru phoenix-ru left a comment

Choose a reason for hiding this comment

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

@andychukse Thanks for your PR! I think it will bring local provider in parity with what authjs already does in terms of redirects

@phoenix-ru phoenix-ru merged commit 5276a97 into sidebase:main Sep 19, 2024
6 checks passed
@zoey-kaiser
Copy link
Member

PR Released in https://github.com/sidebase/nuxt-auth/releases/tag/0.9.3 πŸ₯³

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.

4 participants