DEV Community

Alex Spinov
Alex Spinov

Posted on

Auth.js Has a Free API — Universal Authentication for Any JavaScript Framework

What if one auth library worked with Next.js, SvelteKit, Express, Remix, Solid, and Qwik — with 80+ OAuth providers?

Auth.js (formerly NextAuth.js) is the universal authentication library for JavaScript frameworks.

Why Auth.js

  • Framework-agnostic — Next.js, SvelteKit, Express, SolidStart, Qwik
  • 80+ providers — Google, GitHub, Discord, Apple, and more
  • Database adapters — Prisma, Drizzle, Supabase, MongoDB, DynamoDB
  • Passwordless — email magic links, WebAuthn/passkeys
  • Self-hosted — your data stays on your servers
  • Free and open source — MIT licensed

Quick Start with Next.js

npm install next-auth@beta
Enter fullscreen mode Exit fullscreen mode
// auth.ts
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import Google from "next-auth/providers/google";

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [
    GitHub({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }),
    Google({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET }),
  ],
});
Enter fullscreen mode Exit fullscreen mode
// app/page.tsx
import { auth, signIn, signOut } from "@/auth";

export default async function Home() {
  const session = await auth();

  if (!session) {
    return (
      <form action={async () => { "use server"; await signIn("github"); }}>
        <button>Sign in with GitHub</button>
      </form>
    );
  }

  return <p>Welcome, {session.user.name}!</p>;
}
Enter fullscreen mode Exit fullscreen mode

Database Sessions

import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/prisma";

export const { handlers, auth } = NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [GitHub, Google],
  // Sessions are now stored in your database
});
Enter fullscreen mode Exit fullscreen mode

Real Use Case

A developer had auth hardcoded to Next.js with NextAuth v4. When they needed to add a SvelteKit admin panel, they faced rewriting auth from scratch. With Auth.js v5, both apps share the same auth configuration and session store. One auth system, two frameworks.

When to Use Auth.js

  • Self-hosted auth (no vendor lock-in)
  • Multi-framework projects
  • Apps needing many OAuth providers
  • Projects where data sovereignty matters

Get Started

Visit authjs.dev — open source, MIT licensed, 20K+ GitHub stars.


Need custom data pipelines or scraping solutions? Check out my Apify actors or email me at spinov001@gmail.com for custom solutions.

Top comments (0)