Skip to content

Auth SDK for React and Next.js

@rem/auth-react - sign-in, sign-up, recovery and second-factor forms inside your app, Next.js route handlers with PKCE and encrypted cookies, sessions and webhook verification.

@rem/auth-react (0.3.0) lets a Next.js app draw REM Auth's screens itself, so the browser never leaves your domain. The product must be set to in the app under Admin > Products > How people sign in. The forms run REM Auth's real flows: password rules, two-step verification, lock-out, recovery and refusals all behave as on REM Auth's own pages.

Server: one route

// app/api/rem-auth/[...path]/route.ts
import { createRemAuth } from '@rem/auth-react/server';

export const { GET, POST } = createRemAuth({
  url: process.env.REMAUTH_URL!,                 // https://auth.remplatforms.com
  clientId: process.env.REMAUTH_CLIENT_ID!,
  clientSecret: process.env.REMAUTH_CLIENT_SECRET!,
  redirectUri: process.env.REMAUTH_REDIRECT_URI!,
  cookieSecret: process.env.REMAUTH_COOKIE_SECRET!,
  trustedProxyHops: 1,                           // the proxies in front of your app; default: none
}).handlers;

The route does PKCE, exchanges the code, and keeps tokens only in an encrypted httpOnly cookie. Your server calls REM Auth's headless API with the client id and secret; REM Auth only accepts it for products in in-app mode and only towards a registered callback. Writes to the route need the header X-Rem-Auth: 1 (the SDK sends it), which protects against cross-site requests.

Client: the forms

// app/login/page.tsx
'use client';
import { SignInForm } from '@rem/auth-react';

export default function Login() {
  return <SignInForm next="/" links={{ signUp: '/signup', recovery: '/forgot' }} />;
}

Export

What

SignInForm

E-mail or username + password on one screen, then the second factor when set up

SignUpForm

Name, e-mail, password twice, terms; then "check your e-mail"

RecoveryForm

Forgot password: the neutral answer, then a new password from the mailed link

MfaChallenge

Authenticator code, security key or passkey, recovery code

PasswordInput

Eye button, Caps Lock hint, the password rules and "the passwords match" line

useSession()

The signed-in person (claims) or nobody

ProfileMenu

Avatar menu linking to the person's REM Auth account page, with sign-out

const { user } = useSession();
return <ProfileMenu user={user} remAuthUrl="https://auth.remplatforms.com" onSignOut={() => fetch('/api/rem-auth/logout', { method: 'POST', headers: { 'X-Rem-Auth': '1' } })} />;

Redirect mode without the SDK

If you prefer REM Auth's own pages, any OIDC client works: see OIDC endpoints and claims.

Webhooks in Next.js

import { verifyWebhook } from '@rem/auth-react/server';

export async function POST(req: Request) {
  const body = await req.text();
  const event = await verifyWebhook(body, req.headers, process.env.REMAUTH_WEBHOOK_SECRET!); // throws when invalid
  // handle event.type once per event id
  return new Response(null, { status: 204 });
}

See User-change webhooks.

Last updated 18 Nov 2026

Auth SDK for React and Next.js · REM Platforms Blog