# 1. Authentication

### Authentication

#### Check if HAT exists

| Parameters | Type   |
| ---------- | ------ |
| hatDomain  | string |

**Example:**

```typescript
const hatDomain = "testing.hubat.net";
try {
   const res = hat.auth().isDomainRegistered(hatDomain);    
   if (res) {
        // HAT domain is registered
   }   
} catch (e) {
    // HAT domain doesn't exist
}
```

#### Sign out

**Example:**

```typescript
hat.auth().signOut();
```

#### Get HAT domain

**Example:**

```typescript
const res = hat.auth().getHatDomain();    
if (res) {
    // Returns the HAT Domain
    // eg. testing.hubat.net
}
```

#### Get auth token

**Example:**

```typescript
const res = hat.auth().getToken();    
if (res) {
    // Returns the auth token
}
```

#### Check if token has expired

**Example:**

```typescript
const token = '<auth-token>';

if (hat.auth().isTokenExpired(token)) {
    // Token has expired
}
```

#### Generate HAT login URL

**Example:**

```typescript
const hatDomain = 'testing.hubat.net';
const appId = 'our-app-id';
const redirect = 'callback-url';
const fallback = 'fallback-url';

const url = hat.auth().generateHatLoginUrl(hatDomain, appId, redirect, fallback);    
if (url) {
    window.location.href = url;
}
```


---

# 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.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api/1.-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.
