> For the complete documentation index, see [llms.txt](https://on-premises.docs.hyper3d.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://on-premises.docs.hyper3d.ai/authentication/login.md).

# Login

{% hint style="warning" %}
Note that while the backend previously used the `username` field to provide the email address, this has been deprecated in favor of the `email` field.
{% endhint %}

### API Reference

{% openapi src="/files/gJlKKDx0bj3wUm8btUfT" path="/api/user/login" method="post" expanded="true" %}
[openapi3\_0 (5).json](https://4246159311-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJc2Olnfmy17B0BpCm82C%2Fuploads%2Fgit-blob-5050e1639ebc3dccc8449cfb5488b2a8e5510689%2Fopenapi3_0%20\(5\).json?alt=media)
{% endopenapi %}

### Examples

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

const BaseURI = "https://hyperhuman.deemos.com/api"

var client = &http.Client{Timeout: 10 * time.Second}

type CommonError struct {
	Error *string `json:"error,omitempty"`
}

type UserBasicInformation struct {
	UserUUID  string `json:"user_uuid,omitempty"`
	Username  string `json:"username,omitempty"`
	AvatarUrl string `json:"avatar_url,omitempty"`
	Email     string `json:"email,omitempty"`
}

// LoginResponse represents the response from the login endpoint.
type LoginResponse struct {
	CommonError
	UserBasicInformation
	Token string `json:"token,omitempty"`
}

// Login performs JWT-based authentication.
func Login(email, password string) (string, *UserBasicInformation, error) {
	payload := map[string]string{"password": password, "email": email}

	jsonData, err := json.Marshal(payload)
	if err != nil {
		return "", nil, err
	}

	req, err := http.NewRequest("POST", fmt.Sprintf("%s/user/login", BaseURI), bytes.NewBuffer(jsonData))
	if err != nil {
		return "", nil, err
	}

	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		return "", nil, err
	}
	defer resp.Body.Close()

	var responseData LoginResponse
	err = json.NewDecoder(resp.Body).Decode(&responseData)
	if err != nil {
		return "", nil, err
	}

	if responseData.Error != nil {
		return "", nil, fmt.Errorf("error: %s", *responseData.Error)
	}

	return responseData.Token, &responseData.UserBasicInformation, nil
}

func main() {
	email := "example@example.com"
	password := "<your password>"
	token, info, _ := Login(email, password)
	fmt.Println("Logged in successfully. Token:", token, "BasicInformation:", *info)
}

```

{% endtab %}
{% endtabs %}
