Is this performant?
Unanswered
Sokoke posted this in #help-forum
SokokeOP
signIn: async ({ user, account }) => {
const email = user.email;
if (account?.provider === 'github' || account?.provider === 'gitlab') {
const existingUser = await prisma.user.findFirst({
where: {
email: email as string,
},
});
if (!existingUser) {
setTimeout(async () => {
const updateUser = await prisma.user.updateMany({
where: {
email: email as string,
},
data: {
OauthProviderTest: 'update me upon registration',
},
});
}, 3000);
}
}
return true;
},Is waiting 3 seconds before updating the user performant? I'm doing this as a little test/proof of concept before adding all sorts of stripe functions for it. But essentially I'm doing this to add all sorts of extra details in OAuth accounts, as you can do this very easily with credentials but not so easily with OAuth.
I've got the timeout so that it updates the user after the user is created in the database, as if there was no timeout, it would only update on the second login of the account
11 Replies
hmmm if you want a battletested (?) way try using adapter instead of hooking it manually
unless you don't want the hassle of using the adapter
also the signIn callback is not the place to update data
the more correct choice would be in jwt() or session()
the more correct choice would be in jwt() or session()
SokokeOP
actually your right. I'll move this into the session callback and see how well it works
thanks
what might makes you think thats its not performant?
SokokeOP
I suppose the fact that it takes 3 seconds longer, but yeah thinking about it it shouldn't really be an issue
it takes 3 seconds longer because you added a timeout... ?
if you want something done after another, use the
async await feature as opposed to waiting a certain amount of timeunless you want to add a timeout feature like if stripe hasnt responded in 3 ssecondss?
SokokeOP
yeah