Quickstart

Add “Sign in with NIA” to a Next.js app in about ten minutes — register a client, drop in the provider, and read the signed-in user.

Prerequisites

  • A NIA account with access to the client dashboard.
  • An app to add sign-in to (this quickstart uses Next.js — the fastest path; every other stack has a full guide under Choose your stack).

1 · Register your app

Create an OAuth client and copy its client_id and client_secret. Add your redirect URI — Auth.js fixes the path to /api/auth/callback/nia:

redirect URI
# Local development (Next.js dev server runs on :3000)
http://localhost:3000/api/auth/callback/nia

# Production — register your real domain too
https://app.example.com/api/auth/callback/nia
Full details — client types, scopes, rotation — are on Register an application.

2 · Install the library

npm install next-auth @naslabs-ai/nia-next-auth

3 · Configure NIA

Add your credentials to .env.local, then wire the provider.

NIA_ISSUER=https://dev-api.niaauth.com
NIA_CLIENT_ID=your-client-id
NIA_CLIENT_SECRET=your-client-secret
AUTH_SECRET=run: npx auth secret

4 · Add the sign-in button

Trigger the flow with a server action — Auth.js handles the redirect, PKCE, code exchange and callback for you.

app/page.tsx
import { signIn } from "@/auth"

export default function Home() {
  return (
    <form action={async () => { "use server"; await signIn("nia") }}>
      <button type="submit">Sign in with NIA</button>
    </form>
  )
}

5 · Read the signed-in user

any server component
import { auth } from "@/auth"

export default async function Profile() {
  const session = await auth()
  if (!session) return <p>Not signed in</p>
  // session.user.id is the NIA user id (the OIDC `sub`) — stable and immutable.
  // Key your own records on it. The email is a contact attribute and can change.
  return <p>Signed in as {session.user?.email} (id: {session.user?.id})</p>
}
Key your own database on the NIA user id (sub), never on the email — an email address can change, the id never does. That's it — you have working “Sign in with NIA”. Run npm run dev and click the button.

Next steps

  • Choose your stack — full guides for React, Vue, Angular, Django, FastAPI, Spring Boot, .NET, Go, Laravel, and mobile.
  • Protocol — how OAuth 2.0, OIDC, PKCE and scopes work.
  • Developer Tools — decode tokens, generate PKCE, inspect the discovery document.
  • Errors — what each OAuth error means and how to fix it.