oscklmO
Convex Community2y ago
5 replies
oscklm

[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
  },
});
Was this page helpful?