how to automatically refresh a Clerk token in client components?
Asked Answered
J

0

6

The Setup My next.js site using the app router talks to my Django backend, which treats Clerk as the source of truth for users. It does this in part by creating a user when being passed a valid JWT Token, and by the webhooks from Clerk -> Django.

The Problem Any network requests made in a server action done before the payload is sent to the browser is fine - however if a user has the page open for more than 2 minutes I get hit with a token expiry error:

  Options debug, {
    "authStatus": "signed-out",
    "apiUrl": "https://api.clerk.com",
    "apiVersion": "v1",
    "authMessage": "JWT is expired. Expiry date: Sat, 11 May 2024 19:00:48 GMT, Current date: Sat, 11 May 2024 19:08:00 GMT. (reason=token-expired, token-carrier=cookie)",
    "secretKey": "sk_test_*********5b2",
    "authReason": "session-token-outdated"
  }

For the life of me I cant find out where I can refresh this token. In addition to all network requests failing after 2 mins of inactivity, this breaks a periodic poll I have on a page which -- you guessed it -- makes an API call to my server.

  • enabled debug mode on ClerkMiddleware to get the logs
  • Upgraded next.js and Clerk to the latest versions.
  • Prayed and threw salt over my shoulder.
Joell answered 11/5 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.