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 an exact https:// callback on a public host, such as https://myapp.example/. For the steps, see Register an application.

The development server of the starter keeps port 5173 fixed. That local address cannot be the registered callback.

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 the starter at the https URL you registered. http://localhost:5173/ is not a callback you can register.
  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:

FileContent
vite.config.tsAdds the oidc-spa Vite plugin.
src/oidc.tsConnects the library to the issuer https://www.remilia.net/oidc/realms/remilia with VITE_REMILIA_CLIENT_ID.
src/main.tsxRenders the app inside OidcInitializationGate, which waits for the session.
src/App.tsxShows the login button, reads /api/v1/me with the access token, and handles retry and logout.
package.jsonPins oidc-spa 10.2.18.
README.mdRepeats the run steps and the build command.

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://myapp.example/. Register that exact URL. The starter sends the page address as the callback, so opening it at http://localhost:5173/ sends an address the portal rejects.
  • 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