Add values to custom model #1407
Replies: 8 comments 2 replies
-
Yep also not able to add a custom model following the documentation |
Beta Was this translation helpful? Give feedback.
-
I have the same issue sadly :( |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 can you confirm that creating a custom model from the docs example works for you? Happy to provide more info if you need. |
Beta Was this translation helpful? Give feedback.
-
Hi, same here, i tried last night without success following the guide; and also I don't know either how to call the ORM to update my user object once the adapter is written |
Beta Was this translation helpful? Give feedback.
-
One solution i found with mongodb is to use the createUser event, so i add userRole. And then i create a new model for the user profile, this new model is linked with the user by the id. events:
{
createUser: async (message) => {
const client = new MongoClient(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
if (!client.isConnected()) await client.connect();
const dbName = process.env.DATABASE_URL.split('/')
.pop()
.split('?')
.shift();
let usersCollection = client.db(dbName).collection('users');
usersCollection.updateOne(
{ _id: message.id },
{
$set: {
role : 'user'
},
}
);
},
}, |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
@Noudea nice hack, but as we are in a serverless world, this mean we are creating one new db connection on each api call here, don't we? Maybe we can call the db connection from next-auth, and maybe it cares of not creating a new connection each time ? (don't know it this is even possible, i'm not used to "serverless" world) |
Beta Was this translation helpful? Give feedback.
-
@yann-yinn hey salut. Je vois que tu es un des fondateurs de popcorn, mon professeur a travaillé dessus, comme quoi le monde est petit :) !! You are raising very good points here. And i don't really know the solutions. |
Beta Was this translation helpful? Give feedback.
-
Your question
How do I update custom value in custom model
What are you trying to do
I am following guide for extending default User model and added my own user attribute (basically a copypaste of the guide). It is not clear how do I update this attribute (say phoneNumber as in example).
Feedback
Beta Was this translation helpful? Give feedback.
All reactions