# effetch (/docs/reference/effetch)

```ts
import { … } from "@monarcode/session-kit/effetch";
```

Guide: [Effect and effetch](/docs/effect).

## Functions [#functions]

### sessionBearer [#sessionbearer]

An effetch plugin that sends the current access token as `Authorization: Bearer`. After a 401, it gets a new access token once. `GET` and `HEAD` requests are then sent again; other requests return the 401 for you to retry. If the request sent again gets a 401 too, the user is signed out, unless `signOutOnRepeated401` is off. If the renewal ends the session, the call returns the 401.

## Types [#types]

### SessionBearerOptions [#sessionbeareroptions]

Options for [`sessionBearer`](#sessionbearer).

### SessionBearerOptions

Options for sessionBearer.

| Prop                    | Type     | Description                                                                                                                                                                                                                                                                    |
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `baseUrl`               | `string` | Your API's URL, usually the effetch client's `baseUrl`. The access token goes only to requests on its origin.                                                                                                                                                                  |
| `optional?`             | `union`  | Whether a call made while signed out is sent without an `Authorization` header, rather than failing with `UNAUTHENTICATED`. Set `true` when one client serves public and private endpoints. A locked client still fails with `LOCKED`. Calls can override it. Default: `false` |
| `signOutOnRepeated401?` | `union`  | Whether a second 401, after a successful refresh, signs the user out. Set `false` when some endpoints answer 401 for reasons other than a rejected token. Calls can override it. Default: `true`                                                                               |

### SessionBearerPlugin [#sessionbearerplugin]

The plugin [`sessionBearer`](#sessionbearer) returns. Its calls can fail with `AuthFailure`, and `Fetch.make` needs the `Auth` service.