-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
28 lines (23 loc) · 868 Bytes
/
token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use server";
import jwt from "jsonwebtoken";
const TINYBIRD_SIGNING_TOKEN = process.env.TINYBIRD_SIGNING_TOKEN ?? "";
const WORKSPACE_ID = process.env.TINYBIRD_WORKSPACE ?? ""; // Get this ID by running `tb workspace current`
const PIPE_ID = "top_airlines"; // The name of the pipe you want to consume
// Server function that generates a JWT
// All the Tinybird related data won't be visible in the browser
export async function generateJWT() {
const next10minutes = new Date();
next10minutes.setTime(next10minutes.getTime() + 1000 * 60 * 10);
const payload = {
workspace_id: WORKSPACE_ID,
name: "my_demo_jwt",
exp: next10minutes.getTime() / 1000, // Token only valid for the next 10 minutes
scopes: [
{
type: "PIPES:READ",
resource: PIPE_ID,
},
],
};
return jwt.sign(payload, TINYBIRD_SIGNING_TOKEN);
}