#How can I save additional user information like role "vendor" or "customer" in user table when using

1 messages · Page 1 of 1 (latest)

uneven geode
#

How can I save additional user information like role "vendor" or "customer" in user table when using convex google Auth
Google({
profile(res, tokens) {
console.info({ res, tokens });
return {
id: res.sub,
balance: '0',
fullname: res.name,
email: res.email,
type: res.customer,
};
},
}),
onClick={() =>
signIn('google',
{customer: 'vender'}
})
}
As you can see, customer is not default property of google profile....
I tried like this but can received addtional info
please provide me with guidance?

halcyon relic
uneven geode
#

Thanks for your reply.
Can I use createOrUpdateUser function to save additional user info not from google profile?
signIn('google', {
createOrUpdateUser: ,
})
if then please provide me with example

wintry moss
#

Can I use createOrUpdateUser function to save additional user info not from google profile?
I believe it can only access information in the profile of whatever OAuth provider you're using (or data already stored in the DB, like a pre-existing account for the same user). https://next-auth.js.org/providers/google is a good starting point for what fields you do have available

You can store other information in a separate mutation after authenticating (https://labs.convex.dev/auth/authz#get-currently-signed-in-user-id)

Documentation

surreal moat
#

This is how I do it! If user already exist, just update his login time, or new users, assign accessLevel 0.

export const { auth, signIn, signOut, store } = convexAuth({
  providers: [Facebook],
  callbacks: {
    async createOrUpdateUser(ctx, args) {
      if (args.existingUserId) {
        await ctx.db.patch(args.existingUserId, { updatingTime: Date.now() });
        return args.existingUserId;
      }

      return ctx.db.insert("users", {
        ...args.profile,
        accessLevel: 0,
        updatingTime: Date.now(),
      });
    },
  },
});