Skip to content

Conversation

@phoenix-ru
Copy link
Collaborator

πŸ”— Linked issue

Closes #1046

❓ 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

This adds the automatic detection of definePageMeta({ auth: true }) and definePageMeta({ auth: {} }) and attaching the middleware to such pages.

πŸ“ Checklist

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 28, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@sidebase/nuxt-auth@1054

commit: f7c6711

Comment on lines +91 to +94
// Redirect path was provided
if (options.navigateUnauthenticatedTo) {
return navigateTo(options.navigateUnauthenticatedTo)
}
Copy link
Member

Choose a reason for hiding this comment

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

question: Don't we lose the callback url then? E.g. if I send someone to a custom register / signin page this could be seen as a breaking behaviour change right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I have checked and the behaviour seems to be exactly as expected - navigateUnauthenticatedTo only applies for non-logged-in users. If you do the following on a register/signin page:

definePageMeta({
  navigateUnauthenticatedTo: '/',
})

then yes, it will behave exactly like that.

The authjs sign-in is using the error parameter, meaning that it will redirect to the login page and not to the configured navigateUnauthenticatedTo. This seems to not be what users expect in such a case: #1046

@phoenix-ru phoenix-ru merged commit 0088492 into main Sep 4, 2025
7 checks passed
@phoenix-ru phoenix-ru deleted the feat/1046-middleware-behavior branch September 4, 2025 09:53
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.

Struggling to implement many settings/customisations

3 participants