oscklm
oscklm5mo ago

[ConvexAuth]: additional fields passed to signIn, added to user document?

Hello, Is there a way to pass additional sign up values passed to signIn from useAuthActions like for example, here when i sign up my user, i let them define a name in my signup component.
await signIn('password', {
flow: 'signUp',
email: trimmedEmail,
password: trimmedPassword,
name: trimmedName,
});
await signIn('password', {
flow: 'signUp',
email: trimmedEmail,
password: trimmedPassword,
name: trimmedName,
});
I'm unsure where to get the name from, since its not passed to args.profile etc?
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Password,
],
callbacks: {
async createOrUpdateUser(ctx, args) {
if (args.existingUserId) {
await ctx.db.patch(args.existingUserId, {
email: args.profile.email,
phone: args.profile.phone,
// Name goes here
});
return args.existingUserId;
} else {
return await ctx.db.insert('users', {
role: 'user',
email: args.profile.email,
// Name goes here
});
}
},
},
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Password,
],
callbacks: {
async createOrUpdateUser(ctx, args) {
if (args.existingUserId) {
await ctx.db.patch(args.existingUserId, {
email: args.profile.email,
phone: args.profile.phone,
// Name goes here
});
return args.existingUserId;
} else {
return await ctx.db.insert('users', {
role: 'user',
email: args.profile.email,
// Name goes here
});
}
},
},
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
9 Replies
erquhart
erquhart5mo ago
Looking at the source, it seems to accept a params object Still looking Yeah in the example code you pasted there, name should be present in args of createOrUpdateUser I think? There's also a new afterUserCreatedOrUpdated event hook that you can use to preserve the existing behavior and just patch afterward, in case that's helpful.
oscklm
oscklmOP5mo ago
I've tried looking all through the args, and nothing seem to indicate there being whatever is passed along aditionally to email args.profile only has:
(property) profile: Record<string, unknown> & {
email?: string;
phone?: string;
emailVerified?: boolean;
phoneVerified?: boolean;
}
The profile returned by the OAuth provider's profile method.
The profile passed to createAccount from a ConvexCredentials config.
The email address to which an email will be sent.
The phone number to which a text will be sent.
(property) profile: Record<string, unknown> & {
email?: string;
phone?: string;
emailVerified?: boolean;
phoneVerified?: boolean;
}
The profile returned by the OAuth provider's profile method.
The profile passed to createAccount from a ConvexCredentials config.
The email address to which an email will be sent.
The phone number to which a text will be sent.
But i might go ahead and give that new callback a try, and see if that gets the data any differently
erquhart
erquhart5mo ago
Yeah it may not work the way I was thinking. Here's an active GitHub discussion validating this problem exists: https://github.com/nextauthjs/next-auth/discussions/901
GitHub
How can I pass additional parameters to signIn() function? · nextau...
Your question How can I pass additional parameters to signIn with email function to use on callback? Cant find passed values on the sign in callback What are you trying to do Im trying to add an ad...
erquhart
erquhart5mo ago
(nextauth is the repo for auth.js)
oscklm
oscklmOP5mo ago
Ahh cool, will take a look. I might just split the signup / complete user info into 2 seperate flows for now, to work around this problem
oscklm
oscklmOP5mo ago
This was the problem solver: https://labs.convex.dev/auth/config/passwords#customize-user-information Totally went past me, even looking at the docs multiple times 🤦‍♂️
Passwords - Convex Auth
Authentication library for your Convex backend
erquhart
erquhart5mo ago
Ah, good find! I haven't used password auth yet, good to know
Mcnoble
Mcnoble4mo ago
I'm facing this issue. Where did you declare or import your CustomPassword.ts file? @oscklm

Did you find this page helpful?