@huddle-ai/auth
v0.2.0
Published
React OAuth 2.0 authorization code flow with PKCE.
Readme
@huddle-ai/auth
A client-side React library for the OAuth 2.0 authorization-code flow with PKCE. The library owns login callback validation, token exchange and renewal, optional provider session logout, scoped token storage, and the optional verification of OpenID Connect ID tokens. A consuming app supplies its provider endpoints and can replace the login, login-callback, and logout views.
Install the package:
npm install @huddle-ai/authThe package ships ESM for modern Vite applications. React and its JSX runtime stay external, and built-in component styles load automatically; no separate CSS import is required.
See the getting-started guide for the public API and the project status for implementation scope and validation. Release notes are in the changelog.
Upgrading from 0.1.1 to 0.2.0
Version 0.2.0 handles interrupted sign-ins: browser Back from the identity provider, a provider access_denied response, and an abandoned provider logout now show a cancelled screen with a Log in or Log out button instead of restarting or showing a dead-end error. The changelog lists every change. If you use the default views and the page components, you do not need to change anything. Otherwise, check these:
- Custom views (
views.LoginView,LoginCallbackView,LogoutView). All three view props gain a'cancelled'status and a requiredonRetry: () => void. Add the new case to any exhaustiveswitchand render a retry button whenstatusis'cancelled'or'error'.LoginCallbackViewandLogoutViewalso receivenavigationError: AuthError | nullandonContinue: () => void; render a Continue button whennavigationErroris notnull. If you build these props by hand in tests or Storybook, add the new fields. See customization for a complete example. - Lifecycle hooks.
onLoginCallbackStartnow runs after the response andstateare validated, not before.onLoginErrorandonLogoutErrorare not called for cancellations (Back,access_denied, an unconfirmed provider logout). See lifecycle. - Direct calls to
completeLogin()orcompleteLogout(). Skip this if you use the library's pages.completeLogin()now returns aLoginResultobject ({ status: 'complete', returnTo }or{ status: 'cancelled' }) instead of a string.completeLogout()can also return{ status: 'cancelled' }. Neither cleans up the callback URL or navigates any more; callcontinueAuthStage(returnTo)afterward, orcontinueAuthStage(null)for a cancellation, and skip it for{ status: 'redirecting' }. - Text assertions. The default login message changed from “Taking you to log in…” to “Logging in…”, and provider
error_descriptiontext is no longer shown to users.
Configuration, routes, and token storage are unchanged.
Run the local consumer fixture
Use two terminals:
npm run dev:mock
npm startOpen the Vite URL, then use Log in, load the protected project, renew the token, and Log out. Logout round-trips through the fixture’s end-session endpoint and stays on the completion page; navigate home to log in again. The fixture uses fake credentials and a locally generated RSA signing key. It is development infrastructure and is not included in the package.
Package and tests
npm run build
npm run test:deploy
npm run test:release
npm run check:router-examples
npm run check:packageThe package is configured for public npm publication. See releasing for the first local publication and automated tag releases. React 19 or later is the only runtime peer dependency; build, router examples, and test tools are development dependencies. Internal auth navigation stays in the current document; the authorization server redirect and callback return still use browser navigation.
Release a new version
Commit your changes on main and make sure your working tree is clean and includes the latest changes from origin/main. Then run:
npm run release-tagThe command bumps the patch version in both package files, creates the release commit, pushes main, and creates and pushes the matching vX.Y.Z tag. You do not need to enter the version or tag yourself. GitHub Actions runs the release checks and publishes to npm under latest; check the Publish to npm workflow in GitHub Actions for the result.
For a larger version bump, run one of these instead:
npm run release-tag -- minor
npm run release-tag -- majorIf a command fails, follow the recovery commands printed by the script instead of rerunning the version bump. See the release guide for setup and troubleshooting.
