Skip to content
exwave.Docs

Components and hooks

Exwave Auth comes with ready-made screens for signing up, signing in, verifying an email and resetting a password. They are copied into your app as source files, so you can change their text, layout and style like any other component.

The logic behind the screens lives in hooks from @exwave-nexus/auth-react. That includes sending the form, showing errors and keeping the session. When you update the package, the screens get its fixes, and your changes to the screens stay.

How you get the screens depends on your app:

With --template next or vite, the screens are in components/exwave/. They use plain React and CSS, with no UI library.

All their styles are in one CSS file: app/globals.css with Next.js, or src/index.css with Vite.

With --template next-shadcn, the screens are shadcn components instead. See the next section.

The shadcn versions of the screens are built from your app’s own shadcn components (Button, Input, Label and Card). They take their colors from your shadcn theme, so they match the rest of your app.

The shadcn CLI copies them into your app from Exwave’s registry: the list of Exwave components that the CLI can install.

If you’re starting from nothing, create Exwave’s shadcn/ui app. It’s a Next.js app with every screen already set up, a home page and an account page. Either command makes the same app:

Terminal window
npm create exwave@latest my-app -- --template next-shadcn
Terminal window
npx shadcn@latest create -t next -n my-app https://www.exwave.net/r/exwave-app.json

Get started lists what’s in the app and where your publishable key goes. The app is already connected to Exwave’s registry, so you can add more Exwave components with npx shadcn@latest add @exwave/<name>.

Your app needs shadcn set up first. If it has no components.json file yet, run npx shadcn@latest init.

  1. Connect your app to Exwave’s registry.

    Run this once in each app:

    Terminal window
    npx shadcn@latest registry add "@exwave=https://www.exwave.net/r/{name}.json"

    This saves the registry’s address in components.json, under the name @exwave. From then on, you can install any Exwave component by name, such as @exwave/sign-in-form.

  2. Add the screens.

    This installs every screen, and the Exwave packages they need.

    Terminal window
    npx shadcn@latest add @exwave/auth-nextjs

    With Next.js, this also creates a page for each screen, such as /sign-in and /sign-up, and the server code that keeps the session. Get started lists every file it adds.

    To add a single screen instead, use its name from the list below:

    Terminal window
    npx shadcn@latest add @exwave/sign-in-form
  3. Connect the screens to Exwave Auth.

    The screens need your publishable key, and <ExwaveProvider> around your app. With React (Vite), they also need a route each. Follow Add Auth to an existing app from step 3.

You don’t need this to use the screens. They already use your app’s colors.

If you’d like your app to look like Exwave’s own app instead, add Exwave’s theme. It has Exwave’s blue, light and dark modes, and the Nunito Sans font. Exwave’s shadcn/ui app already uses it.

  1. If your app isn’t connected to Exwave’s registry yet, do step 1 above.

  2. Add the theme:

    Terminal window
    npx shadcn@latest add @exwave/exwave-theme

    This updates the color variables in your CSS file and installs the font package.

  3. Import the font once, at the top of your root layout. With Vite, put it in your entry file, such as src/main.tsx, instead.

    app/layout.tsx
    import "@fontsource-variable/nunito-sans";
    import "./globals.css";
Component Registry name What it does
<SignInForm /> sign-in-form Signs in with an email or username and a password. If the last session ended, for example because the account was locked, it says why. If the email isn’t verified yet, it offers to send a new link.
<SignUpForm /> sign-up-form Asks for a name, an email and a password, and ticks off your password rules as the person types. Then it asks them to check their email, with a button to resend the link. If sign-up is turned off, it says so.
<VerifyEmail /> verify-email The page that verification emails link to. It verifies the email, signs the person in, and goes to paths.afterSignIn.
<ForgotPasswordForm /> forgot-password-form Sends an email with a link to choose a new password.
<ResetPasswordForm /> reset-password-form The page that password reset emails link to. It saves the new password and signs the person in.
<SignOutButton /> sign-out-button Signs out on this device. With everywhere, it signs out on every device.
<UserButton /> user-button Shows Sign in when nobody is signed in. Otherwise, it shows an avatar with a menu for the account page and signing out.

After signing in, <SignInForm /> goes to the ?redirect= path of the page, such as /sign-in?redirect=/account, when it’s a path on your site.

Apps made with --template next or vite have the same components except <UserButton />. Their account page uses <UserProfile user={user} /> instead, which shows the signed-in user and sign-out buttons.

The screens link to each other, for example from sign-in to “Forgot your password?”. They find each page in the paths of <ExwaveProvider>. These are the defaults:

Path Default
signIn /sign-in
signUp /sign-up
verifyEmail /verify (verification emails link here)
forgotPassword /forgot-password
resetPassword /reset-password (password reset emails link here)
afterSignIn, afterSignOut /

If your pages are somewhere else, change the paths on the provider:

<ExwaveProvider paths={{ afterSignIn: "/dashboard" }}>…</ExwaveProvider>

With Next.js, your server writes the links in the emails. So set verifyEmail and resetPassword on the server instead, in lib/exwave.ts: createExwaveNext({ paths: { verifyEmail: "/auth/verify" } }).

The screens get their error messages, password rules and sign-out reasons from @exwave-nexus/auth/messages, in English. To change some of them, or to translate them, pass your own text to the provider, by key:

<ExwaveProvider
messages={{
"error.invalid_credentials": "Mauvais identifiant ou mot de passe.",
"rule.min_length": "au moins {count} caractères",
}}
>

Text in braces, such as {count}, is filled in for you. Every key and its English text is in defaultMessages, exported from @exwave-nexus/auth/messages. The values must be plain strings, so that a Next.js Server Component can pass them.

Headings, labels and button text are written in the components themselves. Change them there.

To write your own screens, use the same hooks as the components. Each action hook gives you:

  • run(), which sends the request. It never throws: if the request fails, it returns undefined and sets error.
  • pending, which is true while the request runs.
  • error, the error itself, and message, the error as a sentence to show.

This sign-in form uses useSignIn():

import { useExwave, useSignIn } from "@exwave-nexus/auth-react";
export function SignIn() {
const { navigate, paths } = useExwave();
const signIn = useSignIn();
return (
<form
onSubmit={async (event) => {
event.preventDefault();
const form = new FormData(event.currentTarget);
const session = await signIn.run({
login: String(form.get("login")),
password: String(form.get("password")),
});
if (session) navigate(paths.afterSignIn);
}}
>
<input name="login" autoComplete="username" required />
<input name="password" type="password" autoComplete="current-password" required />
{signIn.message && <p role="alert">{signIn.message}</p>}
<button disabled={signIn.pending}>Sign in</button>
</form>
);
}
Hook What it gives you
useExwave() Who is signed in, and the provider’s settings: user, isSignedIn, isLoaded, signOutReason, auth (the client), navigate, paths and messages.
useSignIn() run({ login, password }) to sign in. unverifiedEmail is set when the email isn’t verified yet, so you can offer a new link.
useResendVerification(email) run() to send a new verification link. sent becomes true once it’s sent.
useSignUp() signUp.run({ email, password, displayName }) to sign up. step is "form", then "check_email". Also resend, back(), and policy, the password rules.
useEmailLink() Handles the email link that opened the page. Its status is "loading", "none", "verified", "reset" (with userId and code) or "error".
usePasswordReset() request.run(email) to send a reset link, then request.sent. confirm.run({ userId, code }, password) to save the new password.
useSignOut() run() to sign out on this device, or run({ everywhere: true }) on every device.
usePasswordPolicy(), usePlatformConfig() Your platform’s password rules, and its Auth settings.
usePasswordCheck(password, policy) Checks a password as it’s typed: rules (each with ok and a label), failed and valid.
<SignedIn>, <SignedOut> Show their children only when someone is signed in, or signed out. They show nothing until the session is known.

useEmailLink() reads the code in the link only once the page runs in a browser. Email security scanners often open links without running JavaScript, so they can’t use up the code before the person clicks. It reads the code once, even under React Strict Mode, and then removes it from the address bar.

While you develop on localhost, the hooks warn in the browser console if the page’s address isn’t your Site URL or one of your Redirect URLs. Add it in Nexus → Auth → Settings, or email links won’t open your app.