JWT Authentication

With Vercel's Edge Middleware we're able to authenticate users with JWT tokens before they hit any endpoints, and even to respond directly from the edge.

Below is your assigned user token (a JWT), saved under theuser-token cookie

We'll make a request to /api and /api?edge using your token, where the first will hit an API route and the latter will be handled by the edge, they'll return a nanoid

await fetch('/api?edge')
await fetch('/api')

Below is the result of making a request to both the edge and the API endpoint:

{
  "url": "/api?edge",
  "latency": null,
  "status": null,
  "data": {
    "nanoid": null,
    "jwtID": null
  }
}
{
  "url": "/api",
  "latency": null,
  "status": null,
  "data": {
    "nanoid": null,
    "jwtID": null
  }
}

The latency shown might not be realistic, check the network tab in devtools and filter by /api for better results.