SEQN Auth Next.js Helpers

The Next helper is exported from @seqn/auth-js/next. It avoids importing from next/server, so it can be used in route handlers, server components, and middleware with the Next APIs you already have.

Environment


NEXT_PUBLIC_SEQN_AUTH_BASE_URL=https://accounts.seqn.in
NEXT_PUBLIC_SEQN_AUTH_PUBLISHABLE_KEY=pk_live_your_project_key
SEQN_AUTH_SECRET_KEY=sk_live_your_project_secret

Only the NEXT_PUBLIC_ values belong in browser bundles. Keep SEQN_AUTH_SECRET_KEY server-side.

Server component


import { createSeqnAuthNextHelpers } from "@seqn/auth-js/next";

export default async function Page() {
  const auth = createSeqnAuthNextHelpers();
  const config = await auth.client.loadPublicConfig();
  const hosted = auth.getHostedAuthUrls(null, {
    config,
    returnTo: "https://app.example.com/dashboard"
  });

  return (
    <main>
      <h1>{config.application.name}</h1>
      <a href={hosted.signInUrl}>Sign in</a>
      <a href={hosted.signUpUrl}>Sign up</a>
    </main>
  );
}

Route handler backend check


import { createSeqnAuthNextHelpers } from "@seqn/auth-js/next";

export async function GET() {
  const auth = createSeqnAuthNextHelpers();
  const health = await auth.verifyBackendKeyHealth();
  return Response.json(health, { status: health.ok ? 200 : 503 });
}

Middleware redirect

The helper builds URLs. Your middleware still owns policy and uses NextResponse.


import { NextResponse } from "next/server";
import { createSeqnAuthNextHelpers } from "@seqn/auth-js/next";

export function middleware(request) {
  const auth = createSeqnAuthNextHelpers();

  if (request.nextUrl.pathname.startsWith("/dashboard")) {
    return NextResponse.redirect(auth.createSignInUrl(request));
  }

  return NextResponse.next();
}

This example redirects unconditionally to show the handoff. In production, only redirect when your app has determined the request lacks a valid session.