React components
Drop-in sign-in, sign-up, and account components for React with @meetploy/auth-react.
React components
@meetploy/auth-react gives React apps ready-made auth UI and hooks. It works with Next.js, Vite, TanStack Start, and any other React setup deployed on Ploy.
pnpm add @meetploy/auth-reactSet up the provider
Wrap your app in AuthProvider. It loads the current user and the project's enabled sign-in methods.
import { AuthProvider } from "@meetploy/auth-react";
export function App({ children }: { children: React.ReactNode }) {
return <AuthProvider>{children}</AuthProvider>;
}In Next.js, put it in app/layout.tsx. The components are client components, so they work inside Server Component layouts.
apiUrl defaults to /_ploy/auth. After configuring shared sessions, use <AuthProvider apiUrl="https://auth.example.com/_ploy/auth"> to call a sibling auth host. Requests include credentials; the browser origin must have the same scheme and port and be under the shared domain. Passkeys must be migrated when that domain changes.
Components
| Component | What it renders |
|---|---|
SignInForm | Every enabled method: provider buttons, a passkey button, the email and password form, and Email me a sign-in link |
SignUpForm | Sign-up with every enabled method, including passkey sign-up and extra metadata fields |
UserButton | An avatar that opens a menu with the user's name and email, Manage account, and Sign out |
UserProfile | An account page: profile, password, connected Google, Apple, and GitHub accounts, passkeys, and sign out |
SignedIn | Its children, only when a user is signed in |
SignedOut | Its children, only when nobody is signed in |
All of them follow your project's sign-in methods, so turning a method on in the dashboard shows it everywhere without a redeploy.
A typical header
import { SignedIn, SignedOut, UserButton } from "@meetploy/auth-react";
export function Header() {
return (
<header>
<SignedOut>
<a href="/login">Sign in</a>
</SignedOut>
<SignedIn>
<UserButton userProfileUrl="/account" afterSignOutUrl="/" />
</SignedIn>
</header>
);
}Sign-in and sign-up pages
"use client";
import { SignInForm } from "@meetploy/auth-react";
export default function LoginPage() {
return (
<SignInForm
redirectTo="/dashboard"
onSignUpClick={() => location.assign("/signup")}
/>
);
}SignUpForm takes the same props plus fields, a list of extra metadata fields such as ["name", "company"].
| Prop | Description |
|---|---|
redirectTo | Navigate here after success |
onSuccess, onError | Callbacks with the user or the error |
onSignUpClick / onSignInClick | Show a link to the other form |
theme | "auto" (default), "light", or "dark" |
appearance | Colors, radius, and font; see Theming |
className | Extra class on the root element |
Account page
"use client";
import { UserProfile } from "@meetploy/auth-react";
export default function AccountPage() {
return <UserProfile afterSignOutUrl="/" />;
}Users can change their password (or set one if their account has none), connect another provider (when it is enabled), disconnect one, add and remove passkeys, and sign out. Ploy refuses to remove the last way a user can sign in. Disconnecting a provider also deletes its stored tokens, but does not revoke the grant at the provider. For additional scopes and server-only API access, see social sign-in.
When sign-in links are on, SignInForm offers Email me a sign-in link and then shows a Check your inbox screen. When sign-in codes are on, it offers Email me a sign-in code and then shows We emailed you a code with a 6-digit field that accepts pasting. SignUpForm offers the same email option next to the password and passkey sign-up. Call sendMagicLink(email), sendEmailCode(email), verifyEmailCode(email, code), and changePassword({ currentPassword, newPassword }) from useAuth() to build your own.
Theming
Every component follows the system color scheme by default, and switches to dark mode inside a .dark class (Tailwind's convention). Force a mode with theme="light" or theme="dark".
Change colors, corner radius, and font with appearance, on one component or on AuthProvider for all of them:
<AuthProvider
appearance={{
variables: {
colorPrimary: "#4f46e5",
colorPrimaryHover: "#4338ca",
borderRadius: "12px",
fontFamily: "Inter, sans-serif",
},
hideBranding: true,
}}
>| Variable | CSS custom property |
|---|---|
colorPrimary | --ploy-auth-primary |
colorPrimaryHover | --ploy-auth-primary-hover |
colorPrimaryForeground | --ploy-auth-primary-foreground |
colorBackground | --ploy-auth-background |
colorText | --ploy-auth-foreground |
colorTextSecondary | --ploy-auth-muted |
colorBorder | --ploy-auth-border |
colorInputBackground | --ploy-auth-input-background |
colorInputBorder | --ploy-auth-input-border |
colorDanger | --ploy-auth-danger |
borderRadius | --ploy-auth-radius |
fontFamily | --ploy-auth-font-family |
appearance values apply in both light and dark mode. For different values per mode, set the custom properties in your own CSS instead:
.ploy-auth-root {
--ploy-auth-primary: #4f46e5;
}
.dark .ploy-auth-root {
--ploy-auth-primary: #818cf8;
}Server-side lifecycle hooks
Auth lifecycle hooks run in your worker, not in React. Component sign-up/sign-in flows respect before-hook refusals; the React hooks below only read client auth state.
Hooks
useAuth() exposes the state and every action, for building your own UI:
| Field | Description |
|---|---|
user, isLoading, isAuthenticated | Current session |
config | Enabled methods from /_ploy/auth/config |
redirectError | ploy_auth_error code after a failed social sign-in |
signIn, signUp | Email and password |
signInWithProvider(provider, { redirectTo }) | Start Google, Apple, or GitHub sign-in |
signInWithPasskey, signUpWithPasskey, addPasskey, listPasskeys, removePasskey | Passkeys |
listIdentities, unlinkIdentity | Linked provider accounts |
signOut | Revoke the session |
The session lives in an HttpOnly cookie, so your code does not manage
tokens. AuthProvider checks /me when mounted; it is not a background
keep-alive timer. Browser /me checks renew due sliding
sessions. Verify the user on the server with the PLOY_AUTH
binding or the Next.js
helpers.
How is this guide?
Last updated on