Skip to content

Conversation

giceratops
Copy link

@giceratops giceratops commented Mar 3, 2025

Add support for custom JWT claims.

This allows adding additional claims to the JWT generated by Convex Auth.

To add some context on the use case. This make it possible to verify and use claims in the auth middleware, or other services.

// middleware.ts

import { convexAuthNextjsMiddleware } from "@convex-dev/auth/nextjs/server";
import { jwtVerify } from "jose";
import { NextResponse } from "next/server";

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
  const token = await convexAuth.getToken()
  if (token) {
    const { payload } = await jwtVerify(
      token,
      pubKey, // jwks
      { issuer: "..." } // convex site url
    )
    // use payload...
  }

  return NextResponse.next()
});

export const config = {
  // The following matcher runs middleware on all routes
  // except static assets.
  matcher: [
    "/((?!.*\\..*|_next).*)",
    "/",
    "/(api|trpc)(.*)",
  ],
};

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

vercel bot commented Mar 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
convex-auth-docs ✅ Ready (Inspect) Visit Preview Apr 11, 2025 0:41am

@ghost ghost closed this by deleting the head repository Apr 11, 2025
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant