RayyR
Convex Community2y ago
5 replies
Rayy

How to access mutations/queries from authAdapters in next auth convex setup?

I followed through this https://stack.convex.dev/nextauth-adapter and was able to setup adapters for convex, and my application works just fine.
Currently I am using mutations I created to createUser or stuff like that, but I can see that most of the queries or mutations that I require are already present in the authAdadpter.ts file, so I was wondering how can I use it in my applicaiton?

I try to call it, but I am presented with this error.

Expected 2 arguments, but got 1.ts(2554)
registration.d.ts(202, 36): An argument for 'args' was not provided.
(alias) createUser(ctx: GenericMutationCtx<any>, args: {
    user: {
        password?: string | undefined;
        name?: string | undefined;
        emailVerified?: number | undefined;
        image?: string | undefined;
        email: string;
    };
    secret: string;
}): Promise<...>
import createUser

const user = await createUser({
  //passing user
})


I understand that createUser mutation is wrapped with a custom mutation in authAdapter.ts which requires a secret key (CONVEX_AUTH_SECRET_KEY) , but how can I pass that exactly?

/authAdapter.ts
const adapterMutation = customMutation(mutation, {
  args: { secret: v.string() },
  input: async (_ctx, { secret }) => {
    checkSecret(secret);
    return { ctx: {}, args: {} };
  },
});

function checkSecret(secret: string) {
  if (secret !== process.env.CONVEX_AUTH_ADAPTER_SECRET) {
    throw new Error("Adapter API called without correct secret value");
  }
Learn how to install and configure the Convex adapter for Auth.js as part of getting set up with Convex and Next.js.
Convex Adapter for Auth.js (NextAuth) Setup Guide
Was this page helpful?