Skip to content

Clerk/NextJS interstitial expired tokens #1514

@KylerD

Description

@KylerD

Package + Version

  • @clerk/nextjs

Dependencies + versions

 "dependencies": {
    "@clerk/nextjs": "^4.20.0",
    "next": "^13.4.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/node": "^17.0.12",
    "@types/react": "^18.0.22",
    "@types/react-dom": "^18.0.7",
  }

Description

Hey folks,

My application has a typeahead component which makes requests to an internal /api/places endpoint as the user types.

 async function enterSearch(query: string) {
     await fetch(`/api/places?searchInput=${query}`, {
        method: 'GET'
      });
    }
  }

This is just a simplified example, the actual component has debounce controls etc to manage requests, none the less there is a common issue caused by clerk where by my middleware throws the following error:

 -- Options debug, {
"debug": true,
 "beforeAuth": false,
"afterAuth": false
}
-- authenticateRequest state is interstitial in an API route, {
"status": "interstitial",
"reason": "token-expired",
"message": "JWT is expired. etc...",
"frontendApi": "<frontend-api>",
"publishableKey": "<key>",
"isSatellite": false,
 "domain": "",
"proxyUrl": "",
"signInUrl": "/sign-in",
"isSignedIn": false,
"isInterstitial": true,
"isUnknown": false
}

It seems that the application only recovers from this state when I prevent typing again for about 30-60 seconds. I've tried marking the api endpoint as a public route, ignored route etc but the only way to prevent this error thus far has been to remove the middleware. I was unable to find any documentation about this state or behaviour so would appreciate a steer.

Many thanks,
KD

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions