Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.replyful.com/llms.txt

Use this file to discover all available pages before exploring further.

User identification lets you securely pass user information to the chat widget. This enables personalized conversations, linking chats to your user records, and showing user context to your support team.

How it works

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Your backend   │     │  Your frontend  │     │    Replyful     │
└────────┬────────┘     └────────┬────────┘     └────────┬────────┘
         │                       │                       │
         │  1. Generate token    │                       │
         │<──────────────────────│                       │
         │                       │                       │
         │  2. Return signed JWT │                       │
         │──────────────────────>│                       │
         │                       │                       │
         │                       │  3. replyful.identify │
         │                       │──────────────────────>│
         │                       │                       │
         │                       │  4. Verify & link     │
         │                       │<──────────────────────│
  1. Your frontend requests a token from your backend
  2. Your backend generates a signed JWT using your Identity Secret
  3. Your frontend passes the token to the widget
  4. Replyful verifies the token and links the conversation to the user

Get your identity secret

  1. Go to your Replyful dashboard
  2. Navigate to SettingsSecurity
  3. Copy your Identity Secret
Keep your Identity Secret secure. Never expose it in client-side code.

Generate a token on your backend

Create an API endpoint that generates a signed JWT for authenticated users.
Install the jsonwebtoken package:
npm install jsonwebtoken
Create a token endpoint:
import jwt from 'jsonwebtoken';

const IDENTITY_SECRET = process.env.REPLYFUL_IDENTITY_SECRET;

function generateReplyfulToken(user) {
  return jwt.sign(
    {
      // Required
      userId: user.id,

      // Optional
      email: user.email,
      name: user.name,

      // Custom properties (visible to your support team)
      plan: user.subscription?.plan,
      company: user.company?.name,
    },
    IDENTITY_SECRET,
    {
      expiresIn: '1h',
      algorithm: 'HS256'
    }
  );
}

// Express example
app.get('/api/replyful-token', authenticate, (req, res) => {
  const token = generateReplyfulToken(req.user);
  res.json({ token });
});

Call identify from your frontend

After a user logs in, fetch the token from your backend and pass it to the widget:
async function identifyUser() {
  const response = await fetch('/api/replyful-token', {
    credentials: 'include'
  });
  const { token } = await response.json();

  replyful('identify', { token });
}

// Call after user logs in
identifyUser();

React example

import { useEffect } from 'react';
import { useUser } from './auth';

function ReplyfulIdentify() {
  const { user, isAuthenticated } = useUser();

  useEffect(() => {
    if (!isAuthenticated) return;

    async function identify() {
      const res = await fetch('/api/replyful-token');
      const { token } = await res.json();
      window.replyful?.('identify', { token });
    }

    identify();
  }, [isAuthenticated, user?.id]);

  return null;
}

Token payload

FieldTypeRequiredDescription
userIdstringYesUnique identifier in your system
emailstringNoUser’s email address
namestringNoUser’s display name
*anyNoCustom properties (visible to support)

Security best practices

  1. Never expose your Identity Secret in client-side code
  2. Generate tokens server-side only to prevent tampering
  3. Use short expiration times (1 hour recommended)
  4. Authenticate users before generating tokens
  5. Use HTTPS for all API requests
The widget handles missing or invalid tokens gracefully — users can still chat anonymously.