Get started with Auth
In this guide, you create a web app where people can sign up, verify their email and sign in with Exwave Auth. It takes a few minutes. Already have an app? Go to Add Auth to an existing app.
You need:
- Access to the Auth private beta. If you don’t have it yet, ask for it on the waitlist page.
- A platform in Nexus. An organization owner can create one with Create platform.
- Node.js 20 or later.
Create an app
Section titled “Create an app”-
Turn on Auth and copy your key.
In Nexus, open your platform and go to Auth. Select Turn on Auth, then copy the Publishable key. It starts with
exw_pk_. The key only tells the libraries which platform to use, so it’s safe to put in browser code. -
Allow email links to open your app.
Verification and password reset emails only link to addresses you allow. In Auth → Settings, add your development address to the Redirect URLs:
http://localhost:3000http://localhost:5173 -
Create the app.
Choose Next.js if your site has its own server code. Choose React (Vite) for a single-page app with no server. Replace
exw_pk_...with your key:Terminal window npm create exwave@latest my-app -- --template next --key exw_pk_...Terminal window npm create exwave@latest my-app -- --template vite --key exw_pk_...The command creates a
my-appfolder, installs the dependencies and writes your key to.env.local. With Next.js, it also writes a cookie secret there.No key yet? Leave out
--key. The app then uses the local mock, a stand-in for Exwave Auth that runs on your machine. -
Start the app.
Terminal window cd my-appnpm run devOpen
http://localhost:3000/sign-up(http://localhost:5173/sign-upwith Vite) and create an account. Then open the link in the verification email. You’re signed in, and the home page shows Signed in as with your name.
The sign-in, sign-up, verification and password reset screens are now files
in your app, in components/exwave/. Change them as you like: see
Components.
Create a shadcn/ui app
Section titled “Create a shadcn/ui app”The next and vite templates use plain React and CSS. To build with
shadcn/ui and Tailwind CSS instead, use the
next-shadcn template. It makes a Next.js app with:
- every auth screen, in
app/(auth)/ - a home page that shows who’s signed in
- an account page,
/account, that only signed-in people can open - the server routes the screens call, in
app/api/exwave/[...action]/route.ts proxy.ts, which keeps sessions fresh- Exwave’s colors, in light or dark mode to match the system
First, do steps 1 and 2 above. Then create the app, with
your key in place of exw_pk_...:
npm create exwave@latest my-app -- --template next-shadcn --key exw_pk_...Then run cd my-app and npm run dev, as in step 4. As
with the other templates, leave out --key to use the
local mock.
You can make the same app with the shadcn CLI:
npx shadcn@latest create -t next -n my-app https://www.exwave.net/r/exwave-app.jsonThis writes .env.local with placeholder values. Replace them with your key
and a cookie secret, as in step 3 below.
The screens are in components/exwave/. The app is already connected to
Exwave’s registry, so you can add more Exwave components with
npx shadcn@latest add @exwave/<name>. See
Components.
Add Auth to an existing app
Section titled “Add Auth to an existing app”These steps add Exwave Auth to a Next.js 16 app that uses the App Router, or to a React 19 single-page app. Choose your framework in the tabs.
First, do steps 1 and 2 of Create an app: turn on Auth, copy your publishable key, and add your development address to the Redirect URLs.
Each framework has its own package, built on @exwave-nexus/auth, the
JavaScript client. If you’re using another framework, use
@exwave-nexus/auth on its own (see Without React),
or email [email protected] to ask us to support
it.
The ready-made screens are shadcn/ui components. Not using shadcn? Skip step 2, and build your own screens with the hooks.
-
Install the libraries.
Terminal window npm install @exwave-nexus/auth @exwave-nexus/auth-react @exwave-nexus/auth-nextjs -
Add the screens from Exwave’s registry.
Not using shadcn? Copy
lib/exwave.ts, the route handler andproxy.tsfrom The files instead, then go to step 3.Terminal window npx shadcn@latest registry add "@exwave=https://www.exwave.net/r/{name}.json"npx shadcn@latest add @exwave/auth-nextjsThe first command connects your app to Exwave’s registry. You only run it once per app. The second one adds:
- the screens, in
components/exwave/ - a page for each screen, in
app/(auth)/:/sign-in,/sign-up,/verify,/forgot-passwordand/reset-password app/api/exwave/[...action]/route.ts, the routes the screens calllib/exwave.ts, which sets up Exwave Auth on your serverproxy.ts, which keeps sessions fresh
- the screens, in
-
Set your key and a cookie secret.
The cookie secret encrypts the session cookie. It must be at least 32 characters, and each environment, such as development and production, needs its own. To make one, run:
Terminal window node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"Put your key and the secret in
.env.local. If you did step 2, the file already has both names, with placeholder values to replace..env.local NEXT_PUBLIC_EXWAVE_PUBLISHABLE_KEY=exw_pk_...EXWAVE_COOKIE_SECRET=... -
Add the provider to your root layout.
<ExwaveProvider>gives every screen the session. WithinitialState, the first render already knows who is signed in.app/layout.tsx import { ExwaveProvider } from "@exwave-nexus/auth-nextjs/client";import { exwave } from "@/lib/exwave";export default async function RootLayout({children,}: Readonly<{ children: React.ReactNode }>) {return (<html lang="en"><body><ExwaveProvider initialState={await exwave.getAuthState()}>{children}</ExwaveProvider></body></html>);} -
Read the user on the server.
exwave.getUser()returns the signed-in user, ornull. This page sends people who aren’t signed in to the sign-in page, then back:app/account/page.tsx import { redirect } from "next/navigation";import { exwave } from "@/lib/exwave";export default async function AccountPage() {const user = await exwave.getUser();if (!user) redirect("/sign-in?redirect=/account");return <p>Signed in as {user.displayName}</p>;}To check that it works, run
npm run devand openhttp://localhost:3000/sign-up. Create an account and open the link in the verification email. Then/accountshows your name.
-
Install the libraries.
Terminal window npm install @exwave-nexus/auth @exwave-nexus/auth-react -
Add the screens from Exwave’s registry.
Terminal window npx shadcn@latest registry add "@exwave=https://www.exwave.net/r/{name}.json"npx shadcn@latest add @exwave/auth-reactThe first command connects your app to Exwave’s registry. You only run it once per app. The second one adds the screens to
components/exwave/. -
Set your key.
Put your publishable key in
.env.local. If you did step 2, the file already has the name, with a placeholder value to replace..env.local VITE_EXWAVE_PUBLISHABLE_KEY=exw_pk_... -
Add the provider and a route for each screen.
Verification and password reset emails link to
/verifyand/reset-password, and the screens link to each other. So each screen needs a route at its path:Path Screen /sign-in<SignInForm />/sign-up<SignUpForm />/verify<VerifyEmail />/forgot-password<ForgotPasswordForm />/reset-password<ResetPasswordForm />Then wrap your app in
<ExwaveProvider>, and give it your router’snavigatefunction, so the screens change pages without reloading. With React Router:src/main.tsx import { ExwaveProvider } from "@exwave-nexus/auth-react";import { createRoot } from "react-dom/client";import { createBrowserRouter, RouterProvider } from "react-router";import { ForgotPasswordForm } from "@/components/exwave/forgot-password-form";import { ResetPasswordForm } from "@/components/exwave/reset-password-form";import { SignInForm } from "@/components/exwave/sign-in-form";import { SignUpForm } from "@/components/exwave/sign-up-form";import { VerifyEmail } from "@/components/exwave/verify-email";import { App } from "./app";const router = createBrowserRouter([{ path: "/", element: <App /> },{ path: "/sign-in", element: <SignInForm /> },{ path: "/sign-up", element: <SignUpForm /> },{ path: "/verify", element: <VerifyEmail /> },{ path: "/forgot-password", element: <ForgotPasswordForm /> },{ path: "/reset-password", element: <ResetPasswordForm /> },]);createRoot(document.getElementById("root")!).render(<ExwaveProviderpublishableKey={import.meta.env.VITE_EXWAVE_PUBLISHABLE_KEY}navigate={(to, options) => router.navigate(to, options)}><RouterProvider router={router} /></ExwaveProvider>,);With another router, pass its navigate function the same way. With no router, leave out
navigate: the screens then load each page in full. To use other paths, see The paths the screens use. -
Read the user in any component.
useExwave()tells you who is signed in.isLoadedisfalseuntil the session has been read from the browser.import { useExwave } from "@exwave-nexus/auth-react";export function Greeting() {const { user, isLoaded } = useExwave();if (!isLoaded) return null;return <p>{user ? `Signed in as ${user.displayName}` : "Signed out"}</p>;}To check that it works, run
npm run devand openhttp://localhost:5173/sign-up. Create an account and open the link in the verification email. You’re signed in.
Next steps
Section titled “Next steps”- Components: change the screens, or build your own with the hooks.
- Next.js and React (Vite): how sessions work, and how to protect a page.
- Games & player access tokens: let your game servers know which player is connecting.