-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Custom User Schema/Model ignoring custom fields #891
Comments
Crossed this issue while trying to solve another one. I'm not expert but I just found in the source that the built-in default adapter calls the User constructor with exact args (name, email, image, emailVerified); therefore your custom property will never be seen by your class constructor. The only way I see to workaround this is to create a custom Adapter (https://next-auth.js.org/tutorials/creating-a-database-adapter). In the |
So the problem was that we can't use an oauth profile data to initialize the user object, because of that built-in User constructor in the default TypeORM Adapter like @rjblopes mentioned next-auth/src/adapters/typeorm/index.js Lines 121 to 131 in 582520f
But we can initialize a custom prop with a constant, with a profile prop or with a user prop (that comes from a database) value, all in the jwt callback when But to the value persist to the session, you also have to pass that token.user value returned from the jwt callback to the session callback like this |
Your question
I can't understand why my custom fields for a User are not stored in the database (MongoDB). I'm surely missing a step, but cannot find it in the documentation.
What are you trying to do
These are my relevant snippets. I have added a 'country' field to the default User schema for testing.
I read about the
createUser
event, but it doesn't access the profile information returned from the provider.This is the resulting User:
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
Edit: syntax '^^
The text was updated successfully, but these errors were encountered: