> For the complete documentation index, see [llms.txt](https://docs.dataswyft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api/1.-authentication.md).

# 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;
}
```
