Generating tokens
Creating tokens
To create a token use the createToken function
import { createToken } from "streamthing";
const token = await createToken({
channel: "main",
password: process.env.SERVER_PASSWORD,
});
return token;
Warning
Generating tokens should only ever happen on the server to avoid leaking sensitive information to the client
Full example
import { createToken } from "streamthing";
// api/get-streamthing-token
const token = await createToken({
channel: "main",
password: process.env.SERVER_PASSWORD,
});
return token;
// Somewhere on the client
const res = await fetch("/api/get-streamthing-token");
const data = await res.json();
const stream = createClientStream({
region: process.env.SERVER_REGION,
id: process.env.SERVER_ID,
token: data.token,
});
createToken()
channel
The desired channel
password
The server password used to create the token