@owlmeans/client-auth
v0.1.7
Published
Client-side authentication service providing user auth state and external auth flow setup.
Downloads
25
Readme
@owlmeans/client-auth
Client-side authentication service providing user auth state and external auth flow setup.
Overview
useSelfAuth()— React hook that returns the current authenticated user'sAuthobjectsetupExternalAuthentication()— configure the client to authenticate against an external identity providermodules— pre-built client modules for the auth flow (login, dispatcher)DEFAULT_ALIAS— the auth service alias ('auth')
Installation
bun add @owlmeans/client-authUsage
Access current auth state in a component:
import { useSelfAuth } from '@owlmeans/client-auth'
function UserMenu() {
const auth = useSelfAuth()
return <span>{auth?.userId}</span>
}Set up external authentication (e.g. OIDC redirect):
import { setupExternalAuthentication } from '@owlmeans/client-auth'
// In context setup
setupExternalAuthentication(context, { serviceUrl: process.env.AUTH_URL })API
useSelfAuth(): Auth | null
Returns the current Auth object from the context, or null if not authenticated.
setupExternalAuthentication(ctx, opts?)
Configures the context to redirect to an external identity provider for authentication.
modules
Pre-built ClientModule[] for the auth flow (mirrors @owlmeans/auth-common's modules with client route models).
DEFAULT_ALIAS
Auth service alias: 'auth'.
Product-Viable Integration Notes
- The manager web app imports
DEFAULT_ALIASfrom this package as the client-side guard alias. @owlmeans/web-oidc-rp/auth/pluginsis imported for side effects to register theOIDC_CLIENT_AUTHandGOOGLE_CLIENT_AUTHplugins.- Redirect plugins persist auth control state before leaving the app and restore it before submitting provider query params as
AuthCredentials. - After login, the browser stores a normal OwlMeans bearer token; product authorization is enforced by server gates and handler checks.
Related Packages
@owlmeans/auth—Authtype returned byuseSelfAuth@owlmeans/auth-common— auth module route definitions@owlmeans/server-auth— server-side counterpart
