> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Recognize signed-in customers in the messenger

> Open the messenger already signed in as your customer, so their first message lands on their account and they are never asked who they are.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## What you can do

Open the messenger already signed in as your customer, so their first message lands on their account and they are never asked who they are. Where to find it: Settings → Installations → identity signing; your website and your backend

## Before you start

* A web installation with its public key and allowed website origins.
* The installation's identity signing secret, installation ID and environment ID, stored only on your server.

## Steps

**Step 1**

Add a backend route that only signed-in customers can call. It signs a short assertion for the current customer with the identity signing secret.

**Step 2**

On signed-in pages, pass identity to init as a function that calls that route and returns the assertion. The messenger waits for it before it starts a session.

**Step 3**

When a customer signs in later on the same page, call identify with a fresh assertion. When they sign out, call logout.

**Step 4**

Test with a fresh browser: sign in, open the messenger and send a message. The conversation shows under that customer in Support and no name or email card appears.

## Example

A customer signed in to your dashboard asks a question; your team sees their account and earlier conversations immediately.

## Things to know

* The assertion is an HS256 JWT. Claims: aud stackshift-support-widget, installation\_id, environment\_id, external\_user\_id (your stable user ID), a unique jti, iat and exp. exp must be at most 5 minutes after iat; 30 seconds of clock skew is allowed.
* Each assertion works once. A function lets the messenger ask for a new one whenever it needs it: when the first try fails and when the customer's Support session has to be renewed. A plain string is used once at start-up.
* A conversation the visitor started before signing in moves to their account when they are identified.
* Anonymous visitors get the answer first. The optional name and email card only appears after your AI or team has replied, and never for identified customers.

## Code

```html Browser theme={null}
<script src="https://support.stackshift.cloud/sdk/support.iife.js"></script>
<script>
  StackshiftSupport.createSupport().init({
    installationKey: "spk_live_...",
    messengerOrigin: "https://support.stackshift.cloud",
    apiOrigin: "https://api.stackshift.cloud",
    identity: () =>
      fetch("/support-identity", { method: "POST", credentials: "include" })
        .then((response) => response.json())
        .then((body) => body.assertion),
  });
</script>
```

```javascript Sign the assertion on your server theme={null}
import jwt from "jsonwebtoken";
import { randomUUID } from "node:crypto";

export function supportAssertion(user) {
  return jwt.sign(
    {
      installation_id: process.env.SUPPORT_INSTALLATION_ID,
      environment_id: process.env.SUPPORT_ENVIRONMENT_ID,
      external_user_id: user.id,
    },
    process.env.SUPPORT_IDENTITY_SECRET,
    { algorithm: "HS256", audience: "stackshift-support-widget", expiresIn: "2m", jwtid: randomUUID() },
  );
}
```

```python Python theme={null}
import os, time, uuid
import jwt

def support_assertion(user_id: str) -> str:
    now = int(time.time())
    return jwt.encode(
        {
            "aud": "stackshift-support-widget",
            "installation_id": os.environ["SUPPORT_INSTALLATION_ID"],
            "environment_id": os.environ["SUPPORT_ENVIRONMENT_ID"],
            "external_user_id": user_id,
            "jti": str(uuid.uuid4()),
            "iat": now,
            "exp": now + 120,
        },
        os.environ["SUPPORT_IDENTITY_SECRET"],
        algorithm="HS256",
    )
```

```go Go theme={null}
import (
	"os"
	"time"

	"github.com/golang-jwt/jwt/v5"
	"github.com/google/uuid"
)

func supportAssertion(userID string) (string, error) {
	now := time.Now()
	claims := jwt.MapClaims{
		"aud":              "stackshift-support-widget",
		"installation_id":  os.Getenv("SUPPORT_INSTALLATION_ID"),
		"environment_id":   os.Getenv("SUPPORT_ENVIRONMENT_ID"),
		"external_user_id": userID,
		"jti":              uuid.NewString(),
		"iat":              now.Unix(),
		"exp":              now.Add(2 * time.Minute).Unix(),
	}
	return jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(os.Getenv("SUPPORT_IDENTITY_SECRET")))
}
```

```php PHP theme={null}
use Firebase\JWT\JWT;

function support_assertion(string $userId): string
{
    $now = time();
    return JWT::encode([
        'aud' => 'stackshift-support-widget',
        'installation_id' => getenv('SUPPORT_INSTALLATION_ID'),
        'environment_id' => getenv('SUPPORT_ENVIRONMENT_ID'),
        'external_user_id' => $userId,
        'jti' => bin2hex(random_bytes(16)),
        'iat' => $now,
        'exp' => $now + 120,
    ], getenv('SUPPORT_IDENTITY_SECRET'), 'HS256');
}
```

## What happens next

> [!TIP]
>
> Signed-in customers start every conversation under their own account, on every page and device.

## If something goes wrong

> [!WARNING]
>
> * The messenger shows a connection problem on a signed-in page: check that your route returns a fresh assertion for this installation and environment, and that your server clock is correct.
> * The wrong customer appears: make sure external\_user\_id is your stable user ID and that sign-out calls logout.

## Related guides

> [card] [Integrate Support into a website or mobile app](https://docs.stackshift.cloud/stackshift-support/developer-web-and-mobile.md)
>
> A developer checklist for connecting customer identity, the messenger and notifications.

> [card] [Add chat to your website](https://docs.stackshift.cloud/stackshift-support/website-widget.md)
>
> Put a Support chat window on your website and send messages to your team.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.