> ## Documentation Index
> Fetch the complete documentation index at: https://developer.watson-orchestrate.ibm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# updateAuthToken()

Replaces the current JWT authentication token with a new one for continued secure communication. This is commonly used when tokens expire or are refreshed during a session.

## Syntax

```javascript theme={null}
instance.updateAuthToken(token);
```

## Parameters

<ParamField path="token" type="string" required>
  The new JWT token to be set in the chat configuration.
</ParamField>

## Returns

<ResponseField name="void">
  Returns a `void` operator.
</ResponseField>

## Examples

The following examples show different ways to update the authentication token:

```javascript theme={null}
// Update token when it expires
instance.on('authTokenNeeded', async (event, instance) => {
    const newToken = await fetchNewAuthToken();
    instance.updateAuthToken(newToken);
});

// Proactively refresh token
const refreshToken = async () => {
    const newToken = await getRefreshedToken();
    instance.updateAuthToken(newToken);
};
```

<Card title="Do you need practical examples?" icon="text-align-start" href="https://www.ibm.com/docs/SSAVQO/deploy/web_chat_agent/tutorials/tutorials_lp.html" arrow="true" cta="Learn with walk-throughs" horizontal>
  Learn how to apply the features available for embedded chat into your implementation with guidance and examples.
</Card>
