Rayy
Rayy8mo ago

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
})
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");
}
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");
}
Convex Adapter for Auth.js (NextAuth) Setup Guide
Learn how to install and configure the Convex adapter for Auth.js as part of getting set up with Convex and Next.js.
4 Replies
Michal Srb
Michal Srb8mo ago
Where are you trying to call the mutation from? 1. Client-side (React) 2. Next.js server 3. Convex (Actions) ?
Rayy
RayyOP8mo ago
@Michal Srb, Next.js server
Michal Srb
Michal Srb8mo ago
From Next.js server code you can:
await ConvexAdapter.createUser(args)
await ConvexAdapter.createUser(args)
Rayy
RayyOP8mo ago
It was that easy, lol. Thank you.
Cannot invoke an object which is possibly 'undefined'.ts(2722)
'ConvexAdapter.createUser' is possibly 'undefined'.ts(18048)
Cannot invoke an object which is possibly 'undefined'.ts(2722)
'ConvexAdapter.createUser' is possibly 'undefined'.ts(18048)
I am getting this typescript error tho? Solved it @Michal Srb , thanks again.

Did you find this page helpful?