Can I save more user data with NextAuth than simply what my provider gives?

I want to save a username as well as the slug for the user's homepage, but can't figure out how to do this. Things break when I add these to my model, telling me Invalid p.user.create() invocation in at the user creation invocation
6 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
jack
jack3y ago
ah ok i see what is the best way to handle something like this? i was considering making a custom user model that just relates to the generated one, but unsure if this is unnecessarily complex and if i just extend, when do i populate? finding a lot of conflicting info via google search
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
jack
jack3y ago
hmm ok that makes sense. so i'm trying to do this but it seems this event isn't being run for some reason. I look at my terminal, and every signout throws this session error, but i've not really added any config that would make sense for this to be thrown:
(sessionToken) => p.session.delete(
An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
(sessionToken) => p.session.delete(
An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
jack
jack3y ago
export const authOptions: NextAuthOptions = {
events: {
createUser: async (message) => {
console.log("CREATING USER");
// const { user } = message;
// const username = generateUsername(user?.name ?? "");
// const slug = slugify(username);
// const updatedUser = await prisma.user.update({
// where: { id: user.id },
// data: { username: username, pageSlug: slug },
// });
// console.log("user created: ", updatedUser);
},
},
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
},
// Configure one or more authentication providers
adapter: PrismaAdapter(prisma),
providers: [
GitHub({
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
}),
],
};

export default NextAuth(authOptions);
export const authOptions: NextAuthOptions = {
events: {
createUser: async (message) => {
console.log("CREATING USER");
// const { user } = message;
// const username = generateUsername(user?.name ?? "");
// const slug = slugify(username);
// const updatedUser = await prisma.user.update({
// where: { id: user.id },
// data: { username: username, pageSlug: slug },
// });
// console.log("user created: ", updatedUser);
},
},
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
},
// Configure one or more authentication providers
adapter: PrismaAdapter(prisma),
providers: [
GitHub({
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
}),
],
};

export default NextAuth(authOptions);
this is my config ok i think it actually may have been the order in which i was logging out/deleting my user, it's running now
Want results from more Discord servers?
Add your server