Closed Richard87 closed 1 year ago
Hello @Richard87 and thank you for the feedback.
Based on the package.json
you provided, you are using @clerk/nextjs@4.19.x
. The support of @clerk/nextjs@4.21.0. I would suggest you upgrade.
Also based on your snippets and the error message it seems that even though the aud
claim exists in the session token, you don't provide an audience
parameter to validate against it in your backend. To support the audience verification you should pass an audience?: string | string[];
parameter to authMiddleware()
with the allowed audiences.
Could you take a look at the above and let me know if your issue is resolved?
Some extra notes:
await clerkClient.users.getUser(userId);
upon each request since this would cause it to reach the request rate limits. You could add the extra information to the session token claims (eg "roles": "{{publicMetadata.roles}}"
) if they are required{secretKey: process.env.CLERK_SECRET_KEY}
from getAuth()
since it's been done internallyWhen upgrading to Next 13.4.0 to 13.4.12 I get this error when using getServersideProps... So no idea whats going on there! Will open a issue on MUI and see if they have any idea...
@dimkl Thanks for helping out, will useUser or useSession also trigger request rate limits? I see they both also include the User object?
Is there a way to get the current session token/claims without useUser/useSession?
@Richard87 I believe that useSession
/ useUser
are client-side components, where there aren't request rate limits since those requests are triggered by the Browser of the end-user.
The request rate limits (I mentioned in my previous) comment are related to the request to server-to-server requests between your server and Clerk backend API.
Do you need the current session token/claims in the server?
Hi, @dimkl , thanks thats what I need to know! I have roles
and member_id
in public metadata, also in the session token, but as long as I can use useUser / useSession
I'm good to go!
When I upgraded Clerk and added audience
to the middleware the error went away! Thank you for the assistance :)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Frontend API:
pk_test_cGVyZmVjdC1nb3JpbGxhLTk4LmNsZXJrLmFjY291bnRzLmRldiQ
Package + Version
@clerk/clerk-js
@clerk/clerk-react
@clerk/nextjs
@clerk/remix
@clerk/types
@clerk/themes
@clerk/localizations
@clerk/clerk-expo
@clerk/backend
@clerk/clerk-sdk-node
@clerk/shared
@clerk/fastify
@clerk/chrome-extension
gatsby-plugin-clerk
build/tooling/chore
Dependencies + versions
Provide a json with the dependencies used in your project (copy paste from yarn.lock / package-lock.json) or a github project / template that reproduces the issue.
*Include the @clerk/ packages and their versions!**
Example:
Browser/OS
Chrome:
Versjon 114.0.5735.198 (Offisiell delversjon) (arm64)
Node:v16.20.1
Cloudflare worker: no idea how to checkDescription
When a custom "aud" claim is added to the session token:
Invalid JWT audience claim (aud) \"http://localhost:3000\". Expected \"undefined\". Make sure that this is a valid Clerk generate JWT. (reason=token-verification-failed, token-carrier=cookie)",
My
pages/minside/test
file: Note: This works great without the customaud
, but its required for the backend apiMy
pages/_app.tsx
file:And my middleware.ts file: