GatelitSigned scheme lets your backend act as the token authority. Your server signs a compact JWT using your GATELIT_SIGNING_SECRET, returns it to the frontend, and the frontend includes it in the Authorization header. The gateway verifies the HMAC signature — no database lookup required.
Tokens expire after their TTL (default 60 seconds). Your frontend should fetch a fresh token before each request rather than caching one for reuse.
How it works
1
Install the SDK
Install
@gatelit/sdk in your backend project.2
Create a token endpoint
Add a server route that authenticates the current user and returns a signed token. The example below uses a Nuxt server route, but the same pattern applies to any Node.js or edge runtime (Next.js API routes, Express, Hono, etc.).
3
Use the token on the frontend
Pass a
getToken callback to GatelitClient. The callback is called before every request, so the gateway always receives a fresh token.signToken reference
signToken uses the Web Crypto API — available natively in Node.js 18+ and all edge runtimes (Cloudflare Workers, Vercel Edge, Deno).
Options
Token format
The returned string is a compact dot-separated value:base64url(header).base64url(payload).base64url(signature) — structurally identical to a standard JWT.
Using the token directly (without the SDK)
If you’re not usingGatelitClient, pass the token in the Authorization header manually:
Token expiry and refresh
Tokens expire at theexp claim embedded in the payload (current time + ttl). When a token expires, the gateway returns a 401. Your getToken implementation should always fetch a new token rather than reusing a cached one to avoid this.