All documentation
Authentication

Client Tokens and Frontend Security

Issue short-lived channel-scoped tokens from a trusted backend and connect browser or mobile clients without exposing project secrets.

Multi-language

Overview

Client tokens separate trusted server credentials from untrusted frontend code. Your backend authenticates the user using your own login/session system, then asks PulseGrid for a short-lived token describing that user's identifier and allowed channels. The browser receives only that token. This is the recommended pattern for React, Vue, Angular, Vite, vanilla browser JavaScript and React Native/Expo-style clients.

Setup

1. Authenticate the user in your own backend. 2. Decide which PulseGrid channel slugs the user may access. 3. Create a short-lived token with identifier ID, optional label and allowed channels. 4. Return that token to the frontend. 5. Connect with pulsegrid/client. 6. Refresh the token through getToken when your backend issues a replacement. 7. Never send the project secret key to the client.

Code example

Client Tokens and Frontend Security
Trusted Node backend
const token = await pg.tokens.create({
  identifierId: "customer_123",
  identifierLabel: "Customer 123",
  allowedChannels: ["order-1042"],
  expiresIn: 3600,
});

Notes

SDK 0.2.0 browser client supports reconnect, exponential backoff, heartbeat, token-refresh callbacks and an outgoing queue. Client tokens are authorization credentials. Keep them short-lived and scope allowed_channels to what the user really needs.