
Data Platform

This is a template for a Next.js app that uses Clerk for authentication and multi-tenant Tinybird real-time analytics applications.
.env file from the .env.example file and fill in the valuesnpm installnpm run devIn Clerk (Dashboard > Configure > JWT templates) choose the Tinybird JWT template:

Modify the claims to your needs:
{
"name": "frontend_jwt",
"limits": {
"rps": 10
},
"scopes": [
{
"type": "PIPES:READ",
"resource": "<YOUR-TINYBIRD-PIPE-NAME>",
"fixed_params": {
"org": "{{org.slug}}",
"user": "{{user.id}}"
}
}
],
"workspace_id": "<YOUR-TINYBIRD-WORKSPACE-ID>"
}
fixed_params to match the parameter names and values in your Tinybird API endpoints.Example:
NODE endpoint
SQL >
SELECT * FROM ds
WHERE 1
{\% if defined(org) %}
AND org = {{String(org)}}
{\% end %}
{\% if defined(user) %}
AND user = {{String(user)}}
{\% end %}
TYPE endpoint
On your application request a token to Clerk using the tinybird template, where tinybird is the name you gave to the template.
const authentication = await auth()
const { userId, sessionId, getToken } = authentication
const token = await getToken({ template: "tinybird" })
fetch('https://api.tinybird.co/v0/pipes/your_pipe.json', {
headers: {
Authorization: `Bearer ${token}`
}
})
On Sign In, the app authenticates with Clerk, the middleware picks up the session and creates a multi-tenant Tinybird JWT token using the tinybird JWT template from Clerk, finally adds the token to the response headers to be used by the application.
Use the token to query Tinybird as the authenticated user.
fixed_params feature.Please open an issue or submit a pull request.
Join the Tinybird Slack community to get help with your project.
Learn more about Tinybird JWT tokens and Clerk.
Copyright © 2025 Tinybird. All rights reserved
|