# @open-pioneer/authentication

> Authentication API for Open Pioneer Trails applications.

Latest version **4.10.0** (published 2026-11-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @open-pioneer/authentication
pnpm add @open-pioneer/authentication
yarn add @open-pioneer/authentication
bun add @open-pioneer/authentication
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.10.0 |
| Published | 2026-11-19 |
| First published | 2023-11-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 6 |
| Unpacked size | 50.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Maintainers | mbeckem_conterra, jessebluemr, antoniave_conterra, open_pioneer |
| Keywords | open-pioneer-trails |

## Links

- npm: https://www.npmjs.com/package/@open-pioneer/authentication
- Repository: https://github.com/open-pioneer/trails-core-packages
- Homepage: https://github.com/open-pioneer
- npm.io page: https://npm.io/package/@open-pioneer/authentication

## Dependencies (6)

- [react](https://npm.io/package/react.md) ^19.3.1
- [@chakra-ui/react](https://npm.io/package/@chakra-ui/react.md) ^3.38.0
- [@open-pioneer/core](https://npm.io/package/@open-pioneer/core.md) 4.10.0
- [@open-pioneer/runtime](https://npm.io/package/@open-pioneer/runtime.md) 4.10.0
- [@open-pioneer/reactivity](https://npm.io/package/@open-pioneer/reactivity.md) 4.10.0
- [@conterra/reactivity-core](https://npm.io/package/@conterra/reactivity-core.md) ^0.8.9

## Recent versions

- 4.10.0 (latest) — 2026-11-19
- 4.10.0-dev.20261119090001 (dev) — 2026-11-19
- 4.7.1-dev-test-snapshot-123.20260821142246 (dev-test-snapshot-123) — 2026-08-21
- 4.7.1-dev-test-snapshot.20260821120534 (dev-test-snapshot) — 2026-08-21
- 4.9.0 — 2026-10-30
- 4.9.0-dev.20261029090037 — 2026-10-29
- 4.9.0-dev.20261002130116 — 2026-10-02
- 4.9.0-dev.20260930055642 — 2026-09-30
- 4.8.0 — 2026-09-17
- 4.8.0-dev.20260910101405 — 2026-09-10
- 4.7.0 — 2026-07-28
- 4.7.0-dev.20260727091735 — 2026-07-27
- 4.7.0-dev.20260713101438 — 2026-07-13
- 4.7.0-dev-test-snapshot.20260707113553 — 2026-07-07
- 4.7.0-dev-test-snapshot.20260707113111 — 2026-07-07
- … 87 more at https://npm.io/package/@open-pioneer/authentication/versions

## README

# @open-pioneer/authentication

This package provides a central service to handle the current user's session.
It cannot be used on its own, but requires an [authentication plugin](#implementing-an-authentication-plugin), that implements the actual authentication flow.

## Usage

### Retrieving the current authentication state

To inspect the current authentication state, inject a reference to the `AuthService` by referencing `"authentication.AuthService"`.

The methods `getAuthState()` and `getSessionInfo()` return information about the current state:

```js
const authService = ...; // injected

// Returns SessionInfo if the user is currently logged in, or undefined otherwise.
const sessionInfo = await authService.getSessionInfo();

// Like the above, but synchronous and includes intermediate states like "pending".
const state = authService.getAuthState();
// Watch the state with the reactivity API or use the useAuthState() hook in React components.
```

### Enforcing authentication

To make sure that only users, that are logged in, can use an application, enforce the authentication flow by wrapping the application with the `<ForceAuth />` component:

```jsx
// AppUI.jsx
import { ForceAuth } from "@open-pioneer/authentication";

export function AppUI() {
    return (
        <ForceAuth>
            <TheRestOfYourApplication />
        </ForceAuth>
    );
}
```

`ForceAuth` renders its children (your application) if the user is authenticated.
Otherwise, it renders the authentication plugin's _fallback_ component (see below).
It is updated if the authentication state changes.

#### _Fallback_

If the user is not logged in, a _fallback_ is shown to the user.
The _fallback_ must be implemented in the authentication plugin.
Depending on the implementation of the authentication plugin,
a fallback can be a login prompt, or a simple message.
Some plugins do not provide a visual fallback but an "effect" instead: an action to perform, such as a redirect to the authentication provider.

Rendering of the login fallback can be customized by passing custom properties (`fallbackProps`) or by supplying a custom render function (`renderFallback`), see the API documentation.

### Triggering logout

To explicitly end the current session, call the `AuthService`'s `logout()` method:

```js
const authService = ...; // injected
authService.logout();
```

### Implementing an authentication plugin

An authentication plugin (providing `authentication.AuthPlugin`) must be present in the application to support authentication.
The plugin implements the actual authentication flow.

The plugin must implement the `AuthPlugin` TypeScript interface exported by this package:

- Provide the current authentication state by implementing `getAuthState()`.
  When authenticated, a user's authentication state contains session information, such as the user's `id`,
  an optional display name and arbitrary additional `attributes` that can be defined by the plugin.

    The state should be implemented based on signals (`@conterra/reactivity-core`).
    This way, updates to the current state are transported automatically.

- Return the login behavior value (a React component or a function to call) by implementing `getLoginBehavior()`.
  This could be a login dialog, a "forbidden" message (_"fallback"_) or a function implementing a redirect ("effect").

- Implement the `logout()` method: this method is called when the user attempts to end their session.

An example is available in this project's `auth-sample`.

## License

Apache-2.0 (see `LICENSE` file)

---
_Source: https://npm.io/package/@open-pioneer/authentication · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
