How to Recognise Logged-In Visitors
Pass your logged-in users to the ChatFlow widget with a signed identity, so they are recognised and continue their conversations without entering a code.
Before you begin
If customers log in to your website or app, ChatFlow can recognise them automatically. Your server signs the user's id, the widget passes it to ChatFlow, and the customer is treated as verified without entering a code. Their earlier conversations on every channel are available to the chatbot, as described in Customer Memory.
Keep the secret on your server
The identity secret must never appear in your web pages, mobile app or browser code. Only the signature goes to the browser. Anyone with the secret could sign in as any of your users in the chat.
1. Create an identity secret
- Sign in as an Owner or Admin.
- Open Chatbots, choose your chatbot, then Publish. In the Identity secret card, select Create identity secret.
- Copy it into your server's configuration (for example an environment variable). ChatFlow shows it once and stores it encrypted. If it is ever exposed, create a new one: the old one stops working immediately.
2. Sign the user id on your server
Compute HMAC-SHA256(secret, userId) as a lowercase hex string. Use a stable id from your system, not an email address that can change.
Node.js
import { createHmac } from 'node:crypto';
const userHash = createHmac('sha256', process.env.CHATFLOW_IDENTITY_SECRET)
.update(user.id)
.digest('hex');Python
import hmac, hashlib, os
user_hash = hmac.new(
os.environ["CHATFLOW_IDENTITY_SECRET"].encode(),
user.id.encode(),
hashlib.sha256,
).hexdigest()PHP
$userHash = hash_hmac('sha256', $user->id, getenv('CHATFLOW_IDENTITY_SECRET'));3. Pass it to the widget
After the ChatFlow script has loaded, call ChatFlow.identify:
<script>
window.ChatFlow.identify({
userId: 'u_12345',
userHash: '<the signature from your server>',
email: 'maya@example.com', // optional
});
</script>Or set it before the script loads:
<script>
window.ChatFlowIdentity = {
userId: 'u_12345',
userHash: '<the signature from your server>',
};
</script>
<script src="https://chat-flow.app/chatflow-chatbot.js" data-chatbot="YOUR_CHATBOT_ID" async></script>The identity is sent once the visitor starts chatting.
What is and is not verified
userIdwith a validuserHashis verified. It links the visitor to their earlier conversations, on any channel, under the same user id.emailis optional and is not covered by the signature, so it is treated as stated, not verified. Customers can still verify an email address with a code in the chat.- An invalid signature is ignored silently. The chat works as normal and the visitor is simply not recognised.
Troubleshooting
| Symptom | Check |
|---|---|
| Visitor is never recognised | Customer Memory is switched on, the secret is the current one, and the signature is computed over exactly the same userId string you pass |
| Console warning "identify() ignored" | userHash must be 64 lowercase hex characters |
| Recognised on one site but not another | Each chatbot has its own secret |
