---
title: "Authentication"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.middag.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

`@middag-io/react` is available from two registries. Choose based on your needs.

<a id="npm-public"></a>

## npm public registry (recommended)

No authentication needed. Install directly:

```bash
npm install @middag-io/react
```

You get the compiled library (`dist-lib/`) and TypeScript type definitions. This is sufficient for building plugins.

Imports, type-checking, extends, and compilation all work normally with the npm public package. Your bundler (Vite, webpack) consumes the ESM bundle and produces your plugin's final build.

<a id="github-packages"></a>

## GitHub Packages (with source)

Includes the full TypeScript source alongside the compiled output. Useful for:

- Navigating into library internals in your IDE
- Reading implementation details of shells, layouts, and blocks
- Contributing to the library

<aside class="middag-container middag-container-info" role="note" aria-label="Access requirement">
<p class="middag-container-title">Access requirement</p>

GitHub Packages requires membership in the [middag-io](https://github.com/middag-io) organization. A token with `read:packages` scope alone is not sufficient — you must have read access to the repository.

</aside>

### Setup

1. Create a GitHub Personal Access Token at [github.com/settings/tokens](https://github.com/settings/tokens)
2. Select the `read:packages` scope (that's all you need)
3. Add to your global `~/.npmrc`:

```bash
echo "@middag-io:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" >> ~/.npmrc
```

4. Install normally:

```bash
npm install @middag-io/react
```

<aside class="middag-container middag-container-warning" role="note" aria-label="Token security">
<p class="middag-container-title">Token security</p>

Always store your token in `~/.npmrc` (global), never in a project-local `.npmrc` file. Project files can accidentally be committed to git, exposing your token.

</aside>

### Verify access

```bash
npm whoami --registry=https://npm.pkg.github.com
```

If this prints your GitHub username, you're configured correctly.

<a id="wizard"></a>

## The wizard handles this

`npx create-middag-ui` asks which registry you want during setup and configures everything automatically. You only need this page if you're setting up manually or troubleshooting.

<a id="ci"></a>

## CI / Docker builds

For CI pipelines and Docker builds where the wizard doesn't run:

### npm public (simplest)

No configuration needed. `npm install` works out of the box.

### GitHub Packages in CI

Set `NODE_AUTH_TOKEN` as an environment variable:

```yaml
# GitHub Actions
- uses: actions/setup-node@v5
  with:
registry-url: https://npm.pkg.github.com
- run: npm ci
  env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

```dockerfile
# Dockerfile
ARG GITHUB_TOKEN
RUN echo "@middag-io:registry=https://npm.pkg.github.com" >> ~/.npmrc && \
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc && \
npm ci && \
rm ~/.npmrc
```

<a id="troubleshooting"></a>

## Troubleshooting

### `401 Unauthorized` during npm install

Your token is invalid or missing the `read:packages` scope.

1. Check your token: `npm whoami --registry=https://npm.pkg.github.com`
2. If it fails, create a new token at [github.com/settings/tokens](https://github.com/settings/tokens) with `read:packages`
3. Update `~/.npmrc` with the new token

### `404 Not Found` for @middag-io/react

The registry scope line is missing or wrong.

1. Check: `grep middag ~/.npmrc`
2. Should show: `@middag-io:registry=https://npm.pkg.github.com`
3. If missing, add it: `echo "@middag-io:registry=https://npm.pkg.github.com" >> ~/.npmrc`

### Switching between registries

To switch from GitHub Packages to npm public:

```bash
# Remove the scope redirect from ~/.npmrc
sed -i '' '/@middag-io:registry/d' ~/.npmrc
# Reinstall
npm install @middag-io/react
```

To switch from npm public to GitHub Packages, follow the [Setup](#github-packages) steps above.

Source: https://docs.middag.dev/middag-react/latest/authentication/index.mdx
