Create a Reach compatible JWT on your backend
const express = require('express');
const jwt = require('jsonwebtoken');
const app = express();
// JWT secret key - get this from Reach
const REACH_SHARED_JWT_SECRET = process.env.REACH_SHARED_JWT_SECRET;
// Middleware to ensure user is authenticated
const authenticateUser = (req, res, next) => {
// Implement your authentication logic here
req.user = {
email: 'user@example.com',
name: 'Example User',
id: 'biz_987654321',
};
next();
};
// Reach authentication endpoint
app.get('/reach-authtoken', authenticateUser, (req, res) => {
try {
const now = Math.floor(Date.now() / 1000);
const payload = {
email: req.user.email,
name: req.user.name,
tenantExternalId: req.user.id, // The user/business ID from your system
partnerId:
'Your unique vertical saas platform identifier provided by Reach',
iat: now,
exp: now + 3600, // 1 hour from now
};
const token = jwt.sign(payload, REACH_SHARED_JWT_SECRET);
res.json({
success: true,
token: token,
});
} catch (error) {
console.error('Error generating token:', error);
res.status(500).json({
success: false,
error: 'Failed to generate token',
});
}
});