Skip to content

Conversation

@lendenmc
Copy link
Contributor

  • Replace FetchConfigurationError throwing with Promise-based error bubbling
  • Add cookie handling to .then() chain for successful responses only
  • Preserve v1.0.0 behavior where HTTP errors reach caller unchanged
  • Fix authentication error handling regression from v1.0.1

Allows .catch((error) => error.data) pattern to work correctly again for normal HTTP error responses like 401 authentication failures.

🔗 Linked issue

Fixes #1047

❓ 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 PR fixes the authentication error handling regression introduced in v1.0.1 where signIn('credentials', {...}) throws "TypeError: Cannot read properties of undefined (reading 'url')" instead of returning proper error responses.

Root Cause:
The change from return $fetch(joinedPath, fetchOptions) to await $fetch.raw(joinedPath, fetchOptions) in v1.0.1 caused HTTP errors to be caught and wrapped in FetchConfigurationError, losing the original error data.

Solution:
Replace the await/try-catch pattern with a Promise chain approach that:

  • Handles cookies for successful responses in the .then() chain
  • Allows HTTP error messages to bubble up to the caller unchanged
  • Preserves the v1.0.0 error handling behavior

Impact:
Restores fine-grained authentication error handling for credentials authentication while preserving the v1.0.1 cookie functionality.

📝 Checklist

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

- Replace FetchConfigurationError throwing with Promise-based error bubbling
- Add cookie handling to .then() chain for successful responses only
- Preserve v1.0.0 behavior where HTTP errors reach caller unchanged
- Fix authentication error handling regression from v1.0.1

Allows .catch((error) => error.data) pattern to work correctly again
for normal HTTP error responses like 401 authentication failures.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 14, 2025

Open in StackBlitz

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

commit: 95f8922

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.

Hi @lendenmc, thank you for a great catch and amazing work with the PR (special thanks for 3 reproduction links!). I tested with the version released by a bot and it does in fact fix the issue 🚀

@phoenix-ru phoenix-ru merged commit 5c6c5f8 into sidebase:main Aug 14, 2025
6 checks passed
@BracketJohn
Copy link
Contributor

Thanks @lendenmc for the great contribution (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants