---
# System prepended metadata

title: Login
tags: [brew-js]

---

---
tags: brew-js
---

# Login

```typescript
import brew from "brew-js/core";
import from "brew-js/extension/login";

interface LoginResponse { }

brew<Brew.WithLogin<LoginResponse>>((app) => {
    app.useLogin({
        cookie: 'my-auth-cookie',
        login(param) {
            // ...
        }
    });
    
    app.on('login', ({ data: LoginResponse }) => {
        console.log(data);
    });
});
```

Combining login and other AJAX calls:

```typescript
interface LoginResponse {
    token: string;
}

brew<Brew.WithLogin<LoginResponse>>((app) => {
    const post = brew.api('post', '/api');
    
    app.useLogin({ /* ... */ });
    
    app.on('login', ({ data: LoginResponse }) => {
        // set the access token to the post method
        // the token will be inserted with Authorization header
        post.token = data.token;
    });
});
```

### `login` event

### `logout` event

### `server-error` error

### `incorrect-cred` error
