Fix: Prevent TypeError when config.providers is undefined #13002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This pull request addresses a runtime error encountered when using
@auth/express
, specifically:Root Cause
The error is caused by the
config.providers
field being undefined when passed togetSession
. ThesetEnvDefaults
function in@auth/core/lib/utils/env.js
expectsconfig.providers
to be an array and attempts to call.map()
on it without null/undefined validation.This happens when
providers: []
is forgotten in the auth configuration, causing the server to crash instead of gracefully handling the missing field.Fix
This PR adds defensive programming to handle cases where
config.providers
is undefined or omitted. The fix ensures that even whenproviders
is forgotten in the auth configuration, the server won't crash:Why it matters
This change prevents server crashes when developers accidentally omit the
providers
field from their auth configuration. Instead of failing with a cryptic TypeError, the application continues to work, making the developer experience much more forgiving.Notes
This change does not modify provider behavior or add any new functionality — it simply ensures the default structure expected by the underlying library is respected.