Light-Auth Logo

Light-AuthAuthentication Made Simple

A lightweight, secure, and easy-to-implement authentication framework for modern web applications. Get started in minutes, not hours.

What is Light-Auth?
A modern authentication framework for server-side rendering applications

Light-Auth is a framework designed to work seamlessly with SSR frameworks like NextJS, Astro, and Nuxt.

It provides a streamlined authentication flow using OAuth2 and OpenID Connect providers such as Google, GitHub, Microsoft ...

Secure

OAuth2/OpenID Connect integration with popular providers

Lightweight

Optimized storage with minimal cookie footprint

Flexible

Authentication entry point made possible from the server side and from the client side

For now, you can use light-auth with

Next.js Logo Next.js,
Astro Logo Astro,
Nuxt.js Logo Nuxt,
SvelteKit Logo SvelteKit and
Express Logo Express
. We are working on adding support for more frameworks in the future.

The code examples shown here is using light-auth server side logic. You can also use the client side logic to call the different
Light Auth Logo Light Auth
endpoints.
npm install light-auth-nextjs
1

TL; DR; Show me the code

Okay, here is the hello world of Light-Auth with Next.js: light-auth-nextjs-sample-one

2

Server Configuration

This file contains the authentication logic and configuration. The exports consts are providers, handlers, signIn, signOut, getAuthSession, and getUser.
These constants are used throughout the application to manage authentication.
./lib/auth.ts
import { Google, Github } from "arctic";
import { CreateLightAuth } from "@light-auth/nextjs";

const googleProvider = {
  providerName: "google",
  arctic: new Google(
    process.env.GOOGLE_CLIENT_ID!,
    process.env.GOOGLE_CLIENT_SECRET!,
    "http://localhost:3000/api/auth/callback/google"
  ),
};


const githubProvider = {
  providerName: "github",
  arctic: new GitHub(
    process.env.GITHUB_CLIENT_ID!,
    process.env.GITHUB_CLIENT_SECRET!,
    "http://localhost:3000/api/auth/callback/github"
  ),
};

export const { providers, handlers, signIn, signOut, getAuthSession, getUser } = CreateLightAuth({
  providers: [googleProvider, githubProvider]
});
3

Authentication Handlers

This file contains the authentication handlers for the API.
These handlers are responsible for processing authentication requests and returning the appropriate responses.
The handlers are exported as GET and POST methods.
./app/api/auth/[...lightauth].ts
import { handlers } from "@/lib/auth";
export const { GET, POST } = handlers;
4

Login Page

This file contains the login page using a form action to login using your provider.
You can also use client components to trigger the login process.
See the documentation Client Components for more information.
./app/login.tsx
import { signIn } from "@/lib/auth";

export default function LoginPage() {
  return (
    <div>
      <form
        action={async () => {
          "use server";
          await signIn("google", "/profile");
        }}
      >
        <button type="submit">login using a form action</button>
      </form>
    </div>
  );
}
5

Profile Page

Retrieves the session information to check if user is authenticated or not and displays it.
./app/profile.tsx
import { getAuthSession } from "@/lib/auth";

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

  return (
    <div>
      {session != null ? (
        <div>
          <p>✅ You are logged in!</p>
          <div>Session Email: {session.email}</div>
          <div>Session Provider: {session.providerName}</div>
        </div>
      ) : (
        <div>
          <p>⚠️ You are not logged in</p>
          <a href="/login"> Go to Login Page </a>
        </div>
      )}
    </div>
  );
}

Trusted by Developers

Hear what others have to say about their experience with Light-Auth.

Never used it... Besides, I don't know what I'm doing here.

S

Sarah C.

CTO at Contoso

Wait, What?? Yet another authentication framework? Are you serious?

D

Dwayne J.

Lead Developer at AdventureWorks

Why do this? I never authenticate my users, I trust the internet.

J

Jim C.

Engineering Manager at Fabrikam

Ready to Get Started?

Choose the plan that's right for your project and start implementing secure authentication today.

Free
$0
Perfect for small projects and personal websites
  • Up to 1,000 monthly active users
  • Email/password authentication
  • JWT token management
  • Community support
Pro
$0/ (yes, it's free)
For growing applications with advanced needs
  • Up to 10,000 monthly active users
  • Social login providers
  • Multi-factor authentication
  • Priority email support
  • Custom branding
Enterprise
$0/ (yes, it's still free, but I have a paypal account)
For large-scale applications with specific requirements
  • Unlimited monthly active users
  • Dedicated support team
  • Custom integration assistance
  • SLA guarantees
  • On-premise deployment option