# Anzar SDK Documentation

## Install The Typescript SDK
In a ts project run the following command to install the anzar package.

**npm**
```bash
$ npm install @anzar-auth/client
```

## Create Anzar Auth Instance
in your main entry file (`main.ts` for example), import Anzar and create your auth instance

```typescript 
import { LocalStorage } from "@anzar-auth/client/adapters";

const anzar = new Anzar(anzarConfig, {
    storage: new LocalStorage(),
    url: "localhost:3000",
    auth: "jwt"
});
```

**`Configuration Options`**

| Attribute | Type             | Required | Description |
|-----------|------------------|----------|-------------|
| `storage` | `StorageAdapter` | Yes      | Adapter used to store and retrieve auth tokens. Use LocalStorage for browser persistence, or provide a custom adapter. |
| `url`     | `string`         | Yes      | Base URL of your Anzar auth server (e.g. "http://localhost:3000" or "https://auth.myapp.com"). |
| `auth`    | `jwt`, `session` | Yes      | Authentication strategy. **`jwt`** uses token-based auth; **`session`** uses server-side sessions. |

---

## Basic Usage
Anzar provides authentication support for email and password.

📝 **Note:** Other methods of authentication will be implemented later

### Sign Up
To sign up a user you need to call the method register with the user's information.
```typescript
const { error, data } = await anzar.Auth.register({ username, email, password });
if (error) {
    console.log(error.message);
}
console.log(data);
```

📝 **Note:** By default, the users are automatically signed in after they successfully sign up.
             Disabling this behavior will be implemented later

### Sign In
To sign in a user you need to call the method login.
```typescript
const { error, data } = await anzar.Auth.login({ email, password });
if (error) {
    console.log(error.message);
}
console.log(data);
```
