rubber-blueR
VAPIβ€’8mo ago
rubber-blue

JWT validation fails and unclear documentation

I've asked a few weeks ago about JWT creation for the webclient, it still seems to be broken. Aside from that the docs seem to have changed and they are now linking to an non existing page.
https://docs.vapi.ai/customization/jwt-authentication

The code:
        const payload = {
          orgId: process.env.VAPI_ORG_ID,
          // This is the scope of the token
          token: {
            tag: 'public',
            restrictions: {
              enabled: process.env.NODE_ENV !== 'development',
              allowedOrigins: [process.env.NEXT_PUBLIC_APP_URL],
              allowedAssistantIds: [assistant.vapiId],
              allowTransientAssistant: false,
            },
          },
        }
        // Get the private key from environment variables
        const key = new TextEncoder().encode(process.env.VAPI_PRIVATE_KEY)

        // Generate the token using a JWT library or built-in functionality
        const token = await new SignJWT(payload)
          .setProtectedHeader({ alg: 'HS256' })
          .setExpirationTime('1h')
          .sign(key)


The JWT validates correctly using the private key, however from the vapi api we receive:

{"message":"Couldn't verify JWT.","error":"Unauthorized","statusCode":401}


It would really help if the docs were complete and include working demo's or examples.
Was this page helpful?