You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a custom user model with NextAuth, following the example in the documentation.
Occasionally I get the error 'Cannot read property 'columns' of undefined', and at other times I get
'Cannot overwrite tag model once compiled'. I can see that the issue is that in the one case the Tag model has not been attached to the mongoose object, and in the latter case it has already been attached and so can't be overwritten. However I'm not sure how to solve this issue.
Here is my custom model:
import Adapters from 'next-auth/adapters';
// Extend the built-in models using class inheritance
export default class User extends Adapters.TypeORM.Models.User.model {
// You can extend the options in a model but you should not remove the base
// properties or change the order of the built-in options on the constructor
constructor(name, email, image, emailVerified) {
super(name, email, image, emailVerified);
}
}
export const UserSchema = {
...Adapters.TypeORM.Models.User.schema,
target: User,
columns: {
...Adapters.TypeORM.Models.User.schema.columns,
username: {
type: String
},
dateOfBirth: {
type: String
},
accountTags: { type: [TagSchema], default: [] },
// the user is fully registered if they've added all their additional details
fullyRegistered: {
type: Boolean,
default: false
}
}
};
My Tag schema looks like this:
import mongoose from 'mongoose';
export const TagSchema = new mongoose.Schema({
name: String
});
const Tag = mongoose.model('tag', TagSchema);
export default Tag;
I have tried adding the Tag to the models in options, but otherwise I'm not sure how to solve the error. What I'm trying to get is for the database to be populated with all of the default fields from NextAuth, but with username, dateOfBirth, accountTags and fullyRegistered too. Any help would be appreciated.
If I can't fix this, I'll likely just create a new schema in my database called UserInformation and link it to NextAuth's User model, but I'd rather have everything together for obvious reasons.
This discussion was converted from issue #1920 on May 04, 2021 17:43.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description 🐜
I'm trying to create a custom user model with NextAuth, following the example in the documentation.
Occasionally I get the error 'Cannot read property 'columns' of undefined', and at other times I get
'Cannot overwrite
tag
model once compiled'. I can see that the issue is that in the one case the Tag model has not been attached to the mongoose object, and in the latter case it has already been attached and so can't be overwritten. However I'm not sure how to solve this issue.Here is my custom model:
My Tag schema looks like this:
Then in my models index.js:
Finally, in my nextauth options ([...nextauth].js)
I have tried adding the Tag to the models in options, but otherwise I'm not sure how to solve the error. What I'm trying to get is for the database to be populated with all of the default fields from NextAuth, but with username, dateOfBirth, accountTags and fullyRegistered too. Any help would be appreciated.
If I can't fix this, I'll likely just create a new schema in my database called UserInformation and link it to NextAuth's User model, but I'd rather have everything together for obvious reasons.
Many thanks,
Raph
Environment 🖥
System:
OS: macOS 11.2.3
CPU: (8) x64 Apple M1
Memory: 174.43 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
Yarn: 1.22.10 - /opt/homebrew/bin/yarn
npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
Browsers:
Chrome: 90.0.4430.93
Safari: 14.0.3
Beta Was this translation helpful? Give feedback.
All reactions