1

I have a Next.js + React app. I have an existing API defined in src/app/api/feature/route.ts. I want to use a command like curl -X POST http://localhost:3000/api/feature -d '{"key": "value"}' -H "Content-type: application/json" to test the endpoint manually from command line. In route.ts we get the Clerk JWT using:

  const { isSignedIn } = await clerkClient.authenticateRequest(req, {
    jwtKey: process.env.CLERK_JWT_KEY,
  });

  if (!isSignedIn) {
    return Response.json({
      "errorMessage": "Invalid JWT provided in Authorization header!"
    }, {
      status: 401
    });
  }

So when I run that POST command, I get the error message: {"errorMessage":"Invalid JWT provided in Authorization header!"}

So, looks like I need the JWT that Clerk generated when I logged into the app in the UI. How do I do that, if that's even the right approach or possible?

1 Answer 1

0

You can log to console the JWT: console.log(request.headers.get('Authorization'));

You should see something like Bearer <JWT> printed off

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.