omzi
omzi•17mo ago

Using Convex with Hanko

I'm trying to get Convex to authenticate my mutations with Hanko but I'm getting an authentication error. Hanko issues JWT tokens which can be easily verified. Here's my current auth config:
const AuthConfig = {
providers: [
{
domain: 'https://545180e5-xxxx-xxxx-xxxx-cece5f3a581d.hanko.io',
applicationID: '...'
}
]
};

export default AuthConfig;
const AuthConfig = {
providers: [
{
domain: 'https://545180e5-xxxx-xxxx-xxxx-cece5f3a581d.hanko.io',
applicationID: '...'
}
]
};

export default AuthConfig;
I'm getting an authentication error from a mutation:
export const createUserData = mutation({
args: {
username: v.optional(v.string()),
firstName: v.optional(v.string()),
lastName: v.optional(v.string()),
bio: v.optional(v.string()),
isOnboarded: v.boolean()
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();

if (!identity) {
throw new Error('Not authenticated!');
}

const userId = identity.subject;
const document = await ctx.db.insert('userdata', {
userId,
username: args.username,
firstName: args.firstName,
lastName: args.lastName,
bio: args.bio,
isOnboarded: args.isOnboarded
});

return document;
},
});
export const createUserData = mutation({
args: {
username: v.optional(v.string()),
firstName: v.optional(v.string()),
lastName: v.optional(v.string()),
bio: v.optional(v.string()),
isOnboarded: v.boolean()
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();

if (!identity) {
throw new Error('Not authenticated!');
}

const userId = identity.subject;
const document = await ctx.db.insert('userdata', {
userId,
username: args.username,
firstName: args.firstName,
lastName: args.lastName,
bio: args.bio,
isOnboarded: args.isOnboarded
});

return document;
},
});
I guess my question now is: Is there something I'm missing? Or is there another way to configure Convex auth?
7 Replies
omzi
omziOP•17mo ago
cc: @jamwt
jamwt
jamwt•17mo ago
can you paste the error you're getting?
omzi
omziOP•17mo ago
Sure. Here:
app-index.js:31 [CONVEX M(document:createDocument)] Uncaught Error: Not authenticated!
at handler (../convex/document.ts:44:4)
app-index.js:31 [CONVEX M(document:createDocument)] Uncaught Error: Not authenticated!
at handler (../convex/document.ts:44:4)
Is there a way to bypass Convex's auth check and implement yours?
jamwt
jamwt•17mo ago
are you at the hackathon, @omzi ?
omzi
omziOP•17mo ago
Yeah, Hanko's 😅 Is Convex holding any?
Michal Srb
Michal Srb•17mo ago
We were at CalHacks. Have you set up your client? Which Convex docs are you following?
ian
ian•17mo ago
You can see more about why setAuth failed by looking at the websocket messages (called sync in the Network tab of the browser dev tools). I haven’t heard of someone using Hanko JWTs with convex yet. One nuance is the JWT needs to be OpenID compliant, which is not as common as you’d hope. Holler if you’re still working on it and want more help. Let us know how your client is being configured

Did you find this page helpful?