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

Unclear why Credentials Provider fails with Database Adapter #10966

Open
swordensen opened this issue May 19, 2024 · 8 comments
Open

Unclear why Credentials Provider fails with Database Adapter #10966

swordensen opened this issue May 19, 2024 · 8 comments
Labels
documentation Relates to documentation

Comments

@swordensen
Copy link

swordensen commented May 19, 2024

What is the improvement or update you wish to see?

The documentation found here https://authjs.dev/getting-started/authentication/credentials and here https://authjs.dev/getting-started/providers/credentials

Does not include any warnings about trying to use credentials provider with a database adapter.

The fact that it's not supported is totally okay, especially considering the stance against using the Credentials provider.

That being said, email/password login is required for my app and it took my several hours to understand why the session object was not being retrieved.

Also next-auth fails setting the session token silently. The only way I discovered the source of my problems is when I turned on debug mode and found this error message:

UnsupportedStrategy: Signing in with credentials only supported if JWT strategy is enabled. Read more at https://errors.authjs.dev#unsupportedstrategy

Is there any context that might help us understand?

Basically, for some reason credentials provider only works with JWT tokens and not database session tokens.

Interestingly, this information is available here: https://next-auth.js.org/providers/credentials but, not on the authjs website. I honestly did not know they were connected.

Does the docs page already exist? Please link to it.

https://authjs.dev/getting-started/authentication/credentials

@swordensen swordensen added documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 19, 2024
@patelvivekdev
Copy link

Is their anyway around here?

Like I want to combine OAuth with Credentials, I manage to do that but it only works with JWT.

@julianortlieb
Copy link

The ai of the documentation has following awnser:

image

But I don't understand this argument, because you can decrypt or hash passwords?

@swordensen
Copy link
Author

swordensen commented May 30, 2024

To be clear; I did not make this issue to discuss the merits of the decision made by the auth.js maintainers. I trust they have good reasons for not supporting credentials and database stored sessions.

I just think it should be very clearly documented because it is easy to assume that it would be supported.

@ThangHuuVu ThangHuuVu removed the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Jun 2, 2024
@ThangHuuVu
Copy link
Member

thanks for the feedback, actually it's a bit deeper in the documentation, you have to look at this page: https://authjs.dev/reference/core/providers/credentials#default-1

Hope that the explanation is clear enough!

It comes with the constraint that users authenticated in this manner are not persisted in the database, and consequently that the Credentials provider can only be used if JSON Web Tokens are enabled for sessions.
The functionality provided for credentials-based authentication is intentionally limited to discourage the use of passwords due to the inherent security risks of the username-password model
...

@swordensen
Copy link
Author

@ThangHuuVu I understand that the notice is available deeper in the documentation.

Maybe I was not clear. I made this issue because I think the warning should be included in the credentials auth guide. Specifically the pages I linked above.

I think most new auth.js users will be following the guide and because the warning is not mentioned and that using database sessions with credentials fails silently by default people will continue to be confused like myself.

@ThangHuuVu
Copy link
Member

@swordensen that's fair, PR is welcome to improve the Getting Started doc 🙌 for the “silently” part, I’d say we already have the debugging guide at the top of our Guide submenu, so that should be enough 🤔

@swordensen
Copy link
Author

@swordensen that's fair, PR is welcome to improve the Getting Started doc 🙌 for the “silently” part, I’d say we already have the debugging guide at the top of our Guide submenu, so that should be enough 🤔

Okay! I am more than happy to make a PR :)

I will reference this issue though. I'm not sure if it should remain closed

@swordensen
Copy link
Author

done and done. I agree that the failing silently is documented well enough! I just added a small comment to the credentials section.

I think these small changes would be sufficient to prevent others from going down the wrong path like I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Relates to documentation
Projects
None yet
Development

No branches or pull requests

4 participants