Next-auth: Custom user model fields

Created on 10 Aug 2020  路  4Comments  路  Source: nextauthjs/next-auth

Describe the bug
I'm trying to add custom fields to the user model using TypeORM. I follow the documentation but new fields are not present.

To Reproduce
I have an user Model

import Adapters from 'next-auth/adapters';

export default class User extends Adapters.TypeORM.Models.User.model {
}
export const UserSchema = {
  ...Adapters.TypeORM.Models.User.schema,
  target: User,
  columns: {
    ...Adapters.TypeORM.Models.User.schema.columns,
    slug: {
      type: 'varchar',
      nullable: true,
    },
  },
};

and I use it in the adapter definition

{
   ...
   adapter: Adapters.TypeORM.Adapter(
    // The first argument should be a database connection string or TypeORM config object
    process.env.DATABASE_URL,
    // The second argument can be used to pass custom models and schemas
    {
      customModels: {
        User: Models.User,
      },
    }),
    ...
}

Expected behavior
The user should have a slug field, but no field is present on DB. What am I doing wrong?

Documentation feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • [x] Found the documentation helpful
  • [ ] Found documentation but was incomplete
  • [ ] Could not find relevant documentation
  • [ ] Found the example project helpful
  • [ ] Did not find the example project helpful
bug

All 4 comments

I found the problem, looking at the code the option is models, not customModels. Relevat documentation should be changed here https://next-auth.js.org/tutorials/typeorm-custom-models#using-custom-models

I found the problem, looking at the code the option is models, not customModels. Relevat documentation should be changed here https://next-auth.js.org/tutorials/typeorm-custom-models#using-custom-models

So did you fix the problem by replacing "customModels" with "models"? It still doesn't work for me

Yes, I did and it's working for me

@ramiel Thanks for highlighting the error in the documentation! I've updated it now.

I think that might have been left over from how it was in an old beta (or maybe just the internal name was used by mistake).

When we have a place for example projects sorted out it would be great to have an example that shows custom models.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Xetera picture Xetera  路  3Comments

loonskai picture loonskai  路  3Comments

jimmiejackson414 picture jimmiejackson414  路  3Comments

ghoshnirmalya picture ghoshnirmalya  路  3Comments

SharadKumar picture SharadKumar  路  3Comments