A lightweight, secure, and easy-to-implement authentication framework for modern web applications. Get started in minutes, not hours.
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 ...
OAuth2/OpenID Connect integration with popular providers
Optimized storage with minimal cookie footprint
Authentication entry point made possible from the server side and from the client side
For now, you can use light-auth with
Astro
,Nuxt
,SvelteKit
andExpress
npm install light-auth-nextjs
Okay, here is the hello world of Light-Auth with Next.js: light-auth-nextjs-sample-one
providers
, handlers
, signIn
, signOut
, getAuthSession
, and getUser
.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]
});
GET
and POST
methods.import { handlers } from "@/lib/auth";
export const { GET, POST } = handlers;
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>
);
}
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>
);
}
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.
Sarah C.
CTO at Contoso
Wait, What?? Yet another authentication framework? Are you serious?
Dwayne J.
Lead Developer at AdventureWorks
Why do this? I never authenticate my users, I trust the internet.
Jim C.
Engineering Manager at Fabrikam
Choose the plan that's right for your project and start implementing secure authentication today.