# Authentication - Android

### Authenticate User (Optional)

You can authenticate the user that is currently logged in before calling **`navigateToOneTalk`**. To do this, you can add an authentication method in the previously created Java Module. (See [Get Started - Android](https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-live-chat-for-react-native/pages/-MP8oEr3FwZYsUAdaKIf#configure-and-initialize-taptalk.io-omnichannel-android-sdk-for-react-native-project)). We will add a `@ReactMethod` named **`authenticateUser`**.

{% code title="OneTalkStarterModule.java" %}

```java
import android.content.Intent;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import org.jetbrains.annotations.NotNull;

class OneTalkStarterModule extends ReactContextBaseJavaModule {

    OneTalkStarterModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @NotNull
    @Override
    public String getName() {
        return "OneTalkStarter";
    }

    @ReactMethod
    void navigateToOneTalk() {
        Intent intent = new Intent(getReactApplicationContext(), OneTalkWrapperActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getReactApplicationContext().startActivity(intent);
    }
    
    @ReactMethod
    void authenticateUser(String name, String email, Callback successCallback, Callback errorCallback) {
        TapTalkLive.authenticateUser(name, email, new TTLCommonListener() {
            @Override
            public void onSuccess(String successMessage) {
                successCallback.invoke(successMessage);
            }
            @Override
            public void onError(String errorCode, String errorMessage) {
                errorCallback.invoke(errorMessage);
            }
        });
    }
}
```

{% endcode %}

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

**`name`**: (String) name of the user to be authenticated

**`email`**: (String) email of the user to be authenticated

**`successCallback`**: (Callback) invoked when the authentication is successful

**`errorCallback`**: (Callback) invoked when an error occurred during authentication
{% endhint %}

You can then call the method from JavaScript as such:

```javascript
NativeModules.OneTalkStarter.authenticateUser(
    'USER_NAME', 
    'USER_EMAIL',
    (successMessage) => {
        // Successfully authenticated user
    },
    (errorMessage) => {
        // An error occurred during authentication
      }
);
```

After successfully authenticated, user will no longer be required to fill name and email to create a case.

### Logout and Clear TapTalkLive Data

You may also add another method when you need to logout and clear all local cached data from Omnichannel SDK. We will name this method **`clearAllTapLiveData`**.

{% code title="OneTalkStarterModule.java" %}

```java
import io.taptalk.taptalklive.TapTalkLive;

class OneTalkStarterModule extends ReactContextBaseJavaModule {

    ...
    
    @ReactMethod
    void clearAllTapLiveData() {
        TapTalkLive.clearAllTapLiveData();
    }
}
```

{% endcode %}

You can then call the method from JavaScript when needed.

```javascript
NativeModules.OneTalkStarter.clearAllTapLiveData();
```


---

# 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/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-live-chat-for-react-native/authentication-android.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.
