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-jsand adds React-specific provider, hooks, and components.
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.
@monocloud/auth-react?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:
@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.
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.