# Authentication

In order to use the abilities of the Javascript SDK in your client app, a TapTalk instance must be initiated in each client app through user authentication with TapTalk.io server. An authenticated user account allows the instance to communicate and interact with the server. The following explains how to authenticate your user with the server.

TapTalk.io's Authentication Flow

![TapTalk.io's Authentication Flow](https://gblobscdn.gitbook.com/assets%2F-LfVupFSqh_qZAY9OiCO%2F-MHKsq4vOlouRa03adbb%2F-MHLTpHao9rfmA05gZO6%2F3cee4ff-Login_Flow2x.png?alt=media\&token=e252a825-bf44-49ef-954d-f2c4a841f154)

When the user logs in to your application, your backend server will have to request an **Authentication Ticket** from TapTalk.io server. TapTalk.io server will return the requested **Authentication Ticket** and **user ID** to your backend server. The client application can then retrieve the ticket from your backend server to implement TapTalk.io's SDK by initializing the SDK using the obtained **Authentication Ticket**.

You can see the documentation on how to obtain Authentication Ticket from TapTalk.io's Server on the [Authentication in TapTalk.io's Server API page](https://docs.taptalk.io/powertalk-chat-sdk-documentation/powertalk-platform-api/authentication).

### Authenticate to TapTalk.io server with an Authentication Ticket <a href="#authenticate-to-taptalk-io-server-with-an-authentication-ticket" id="authenticate-to-taptalk-io-server-with-an-authentication-ticket"></a>

```javascript
taptalk.authenticateWithAuthTicket(AUTH_TICKET, CONNECT_WHEN_SUCCESS, { 
      onSuccess: () => {
           // do action here
      },
      onError: (errorCode, errorMessage) => {
           // do action here
      }
 })
```

{% hint style="info" %}
**Parameters**

**AUTH\_TICKET :** (String) an authentication ticket is required for this method\
**CONNECT\_WHEN\_SUCCESS** :  (Boolean) if set to YES, application will connect to TapTalk.io server after authentication is successfully completed
{% endhint %}

### Check Authentication Status <a href="#check-authentication-status" id="check-authentication-status"></a>

You can check authentication status by calling **`isAuthenticated()`**

```javascript
var isAuthenticated = tapTalk.isAuthenticated();
```

### Logout and Clear TapTalk.io Data <a href="#logout-and-clear-taptalk-io-data" id="logout-and-clear-taptalk-io-data"></a>

Call this method when you need to logout and clear all local cached data from TapTalk.io.

```javascript
taptalk.logoutAndClearAllTapTalkData({
    onSuccess: (response) => {
       // do action here
    }
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.taptalk.io/powertalk-chat-sdk-documentation/powertalk-javascript-sdk/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
