# Login

Login endpoint is required to obtain access to all Private🔒 endpoints. The login process involves three steps which are stated below in brief:

1. **Nonce creation**: Generate a payload using the /auth/nonce endpoint.
2. **Sign the payload**: To sign the payload obtained after accessing the above API, use the [NodeJS SDK](/tech/api-documentation/sdk-reference/nodejs-sdk.md) [`signMsg`](https://github.com/brine-finance/brine-connector-nodejs#login) helper function.
3. **Generate access token**: After generating the signature, the signature & eth address is sent in the /auth/login endpoint.

{% hint style="info" %}
Please visit [tanX website](https://tanx.fi) and create an account using your wallet before proceeding with the below steps.
{% endhint %}

### 1. Nonce Creation <a href="#login-nonce" id="login-nonce"></a>

A nonce is a variable that is generated just once and can be used only one time. Generation of a nonce is the first step of the login process. The payload received in this step will be required in the next one.

#### Endpoint <a href="#endpoint" id="endpoint"></a>

```bash
POST /sapi/v2/auth/nonce/
```

#### Request Body <a href="#request-body" id="request-body"></a>

| Field        | Type   | Mandatory |
| ------------ | ------ | --------- |
| eth\_address | STRING | YES       |

Example:

```json
{
  "eth_address": "Ox"
}
```

#### Response <a href="#response" id="response"></a>

```json
{
  "status": "success",
  "message": "Nonce Acquired",
  "payload": "You’re now signing into tanX Testnet, make sure the origin is https://testnet.tanx.finance (Login-code:YG2DHzDpRncwCZAVRUTrVG)
  "
}
```

### 2. Sign The Payload

In this step you’d be required to sign the “payload” obtained through the first step i.e., “Nonce Creation” 👆. Use “payload” as variable “data” and call the signMsg function ( have a look at the snippet below ) located in use the [NodeJS SDK](/tech/api-documentation/sdk-reference/nodejs-sdk.md). to sign “data” with your private key. A signature that will be required in the third step will be returned at the end of this process.

#### Code snippet <a href="#endpoint-1" id="endpoint-1"></a>

```javascript
import { signMsg } from '@tanx-libs/tanx-connector'

const signedMsg = signMsg(message, privateKey) 
```

### 3.Generate Access Token

The access token (JWT) is used to authenticate your request for private endpoints. This key allows tanX to ensure that the requests are always coming from the rightful owner. Make use of the signature that was returned in the previous step “Sign The Payload” 👆, along with the ethereum address to receive a JWT Access Token.

#### Endpoint <a href="#endpoint" id="endpoint"></a>

```bash
POST /sapi/v2/auth/login/
```

#### Request Body <a href="#request-body-1" id="request-body-1"></a>

| Field           | Type   | Mandatory |
| --------------- | ------ | --------- |
| eth\_address    | STRING | YES       |
| user\_signature | STRING | YES       |

#### Example

```json
{
  "eth_address": "Ox",
  "user_signature": "Ox"
}
```

#### Response <a href="#response-1" id="response-1"></a>

```jsx
{
  status: 'success',
  message: 'Login Successful',
  payload: {
    uid: 'IDDAF4F5E3C7',
    signature: ''
  },
  token: {
    refresh: '',
    access: ''
  }
}
```

## Refresh Token for Login

#### Endpoint

```bash
POST /sapi/v1/auth/token/refresh/ 
```

#### Request body <a href="#request-headers" id="request-headers"></a>

```json
{
    "refresh": "eyJndjiFy8gsi0....wJPnQbr9yX4DR" 
} 
```

#### Response

```json
{
    "status": "success",
    "message": "",
    "payload": {
        "access": "eybdgyr0iOi....gVbdghy7g_Pn3QCU",
        "refresh": "eyJ0eXAiOi....mVeL25ytndhltJL4"
    }
}
```


---

# 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.tanx.fi/tech/api-documentation/account/login.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.
