oscklm
oscklm6mo ago

[ConvexAuth] settings values of custom users fields, on user creation

Hey, i've been looking through the docs. And would imagine settings some values for the fields i have customized on the schema for users, when the users get created. Would be done in the account callback configuration? But looking at the API, i've failed to figure out how to use this callback: I wanna achieve setting some of the custom fields i define when i create a user
import { convexAuth } from '@convex-dev/auth/server';
import { Password } from '@convex-dev/auth/providers/Password';

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
callbacks: {
async createOrUpdateUser(ctx, args) {
// How do i know which account this is for?

// Create a new user
return await ctx.db.insert('users', {
accountId: accountIdFromSomewhere, // Account id from where ?
//..
// my custom fields
role: 'user',
});

// Handle different cases, like updating etc.
},
},
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
import { convexAuth } from '@convex-dev/auth/server';
import { Password } from '@convex-dev/auth/providers/Password';

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
callbacks: {
async createOrUpdateUser(ctx, args) {
// How do i know which account this is for?

// Create a new user
return await ctx.db.insert('users', {
accountId: accountIdFromSomewhere, // Account id from where ?
//..
// my custom fields
role: 'user',
});

// Handle different cases, like updating etc.
},
},
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
4 Replies
v
v6mo ago
existingUserId I believe
v
v6mo ago
v
v6mo ago
Or profile Which both are inside args
oscklm
oscklmOP6mo ago
At first i didn't realize that the accountId was not nessecary, as when the userId is returned they get linked. This is what confused me a bit. Leaving this here for others in the same situation

Did you find this page helpful?