Skip to content

Authentication and sessions

Run the React login starter

Run the downloadable React starter to log in with RemiliaNET, show the connected profile, and log out.

The starter uses the oidc-spa library and the official login button. It suits a first working login in a React web app.

Prerequisites

  • Bun and a browser.
  • An approved Login client with the callback http://localhost:5173/, registered exactly. For the steps, see Register an application.

The development server of the starter keeps port 5173 fixed.

Steps

  1. Download the runnable React starter.
  2. Unzip the archive.
  3. Run bun install in the starter folder.
  4. Copy .env.example to .env.local.
  5. Set VITE_REMILIA_CLIENT_ID in .env.local to your public client ID.
  6. Run bun run dev.
  7. Open http://localhost:5173/.
  8. Select Log in with RemiliaNET.
  9. Complete login and consent at RemiliaNET.
  10. Select Log out.
  11. Log in again with another account.

Result

After login, the starter shows the display name and the handle of the connected user. Its /api/v1/me request returns 200. The profile is a root object, not a data envelope.

After logout, the account disappears. Late login and profile responses from the earlier session do not restore it. After you log in with another account, the displayed profile changes.

When the profile request fails, the starter shows the error and a retry control. It does not show tokens. For more information about missing scopes, see App permissions.

Troubleshooting

If login, the callback, or the profile request fails, match the error to its cause in Login and API requests fail.

Starter source

The starter configures oidc-spa in a Vite React app. Each file holds one part of the integration:

To reuse this configuration in another Vite app, keep these facts:

  • The callback of a Vite app is its base URL with the trailing slash, such as https://yourapp.example/. For local development, register an exact loopback URL or an HTTPS development hostname, verbatim.
  • getAccessToken() renews the access token when needed.
  • A backend validates an ID token before it uses the claims to identify the user. It does not trust identity claims that a browser sends without validation.

For other frameworks, see the oidc-spa documentation.

Next steps