MonoCloud Authentication SDK
    Preparing search index...

    Module @monocloud/auth-react

    MonoCloud Banner
    NPM License: MIT Build Status

    MonoCloud React Authentication SDK – secure authentication for React single-page applications.

    MonoCloud is a modern, developer-friendly Identity & Access Management platform.

    This SDK provides React-friendly authentication for single-page applications. It implements OAuth 2.0 / OpenID Connect with PKCE, and surfaces authentication state, sign-in and sign-out flows, and route protection through a React provider, hooks, and components.

    This package builds on @monocloud/auth-web-js and adds React-specific provider, hooks, and components.

    • React v18+
    • Modern Browsers (Chrome, Edge, Firefox, Safari)
    • A MonoCloud Tenant
    • A Client configured as a Single Page Application (SPA)
    • The application's URL registered in Callback URLs, Sign-out URLs and Cross Origin URLs
    npm install @monocloud/auth-react
    

    Wrap your application with <MonoCloudAuthProvider>.

    import { MonoCloudAuthProvider } from '@monocloud/auth-react';

    export default function Root() {
    return (
    <MonoCloudAuthProvider
    tenantDomain="https://<your-tenant-domain>"
    clientId="<your-client-id>"
    >
    <App />
    </MonoCloudAuthProvider>
    );
    }

    By default the provider automatically processes the OIDC callback when it mounts.

    import { useAuth } from '@monocloud/auth-react';

    export default function Home() {
    const { isLoading, isAuthenticated, user } = useAuth();

    if (isLoading) return <>Loading…</>;
    if (!isAuthenticated) return <>Not signed in</>;

    return <>Welcome, {user?.email}</>;
    }

    useAuth() also exposes the actions signIn, signOut, signInSilent, refreshSession, refetchUserInfo, and getTokens. For lower-level operations use the useClient() hook to access the underlying MonoCloudWebJSClient client.

    import { SignIn, SignUp, SignOut } from '@monocloud/auth-react';

    <SignIn>Sign In</SignIn>
    <SignUp>Sign Up</SignUp>
    <SignOut>Sign Out</SignOut>
    import { Protected } from '@monocloud/auth-react';

    <Protected fallback={<>Sign in to view this.</>}>
    <SecretContent />
    </Protected>

    <Protected> only affects what is rendered on the client. Always enforce authorization on your APIs as well.

    Use @monocloud/auth-react if you are building a React single-page application and want a secure authentication solution with minimal configuration.

    This package is a good fit if you:

    • Are building a React SPA (Vite, Create React App, and similar)
    • Want authentication state and sign-in / sign-out actions accessible anywhere in your component tree
    • Need to conditionally render or gate UI based on the user's authentication status and group membership
    • Want OIDC redirect callbacks handled for you, with optional client-side-router integration on a dedicated callback route
    • Prefer framework-native ergonomics without managing the OAuth / OpenID Connect flow yourself

    @monocloud/auth-react builds on top of @monocloud/auth-web-js, reusing the same browser implementation (PKCE, redirects, popups, silent refresh, and cross-tab coordination) while providing React-specific ergonomics.

    • Use GitHub Issues for bug reports and feature requests.
    • For tenant or account-specific help, contact MonoCloud Support through your dashboard.

    Do not report security issues publicly. Please follow the contact instructions at: https://www.monocloud.com/contact

    Licensed under the MIT License. See the included LICENSE file.

    Classes

    LocalStorage
    MemoryStorage
    MonoCloudWebJSClient
    SessionStorage

    Components

    MonoCloudAuthProvider
    ProcessCallback
    Protected
    SignIn
    SignOut
    SignUp

    Error Classes

    MonoCloudAuthBaseError
    MonoCloudHttpError
    MonoCloudJsError
    MonoCloudOPError
    MonoCloudTokenError
    MonoCloudValidationError

    Hooks

    useAuth
    useClient

    Types

    AccessToken
    Address
    ApplicationState
    AuthorizationParams
    AuthState
    CallbackState
    DefaultAuthParams
    GetTokensOptions
    Group
    IdTokenClaims
    Indicator
    IStorage
    Jwk
    MonoCloudAuth
    MonoCloudAuthProviderProps
    MonoCloudSession
    MonoCloudTokens
    MonoCloudUser
    MonoCloudWebJSClientOptions
    ProcessCallbackProps
    ProtectedComponentProps
    RefreshGrantOptions
    RefreshOptions
    SignInOptions
    SignInProps
    SignInSilentOptions
    SignOutOptions
    SignOutProps
    SignUpProps
    UserinfoResponse

    Types (Enums)

    Authenticators
    ClientAuthMethod
    CodeChallengeMethod
    DisplayOptions
    InteractionMode
    Prompt
    ResponseModes
    ResponseTypes
    SecurityAlgorithms

    Types (Handler)

    OnSessionCreating
    PostCallback