@light-auth/nextjs
v0.3.5
Published
light auth framework for react, using arctic
Maintainers
Readme
Light Auth
Light Auth is a lightweight authentication solution designed for simplicity and ease of integration.
It provides essential authentication features with minimal configuration, making it ideal for small projects, prototypes, or applications that require straightforward user sign-in functionality.
Features
- Simple setup and configuration
- Supports basic authentication flows
- Minimal dependencies
- Easily extensible for custom requirements
- Server side an Client side components
Framework Compatibility
Light Auth shines across your favorite frameworks! Whether you’re building with
| Framework | NPM Package | GitHub Sample |
|-----------------------------------------------|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| Next.js | light-auth-nextjs | Next.js Sample |
|
Astro | light-auth-astro | Astro Sample |
|
Nuxt | light-auth-nuxt | Nuxt Sample |
|
SvelteKit | light-auth-sveltekit | SvelteKit Sample |
|
Express | light-auth-express | Express Sample |
|
Tanstack Start | light-auth-tanstack-react-start | Tanstack Start Sample |
Light Auth integrates seamlessly, letting you add authentication with a sparkle ✨ to any stack!
Getting Started
This getting started is based on the @light-auth/nextjs package.
You will find examples for all others frameworks in each relevant repository
The Light Auth documentation has also a lot of code examples for various scenario.
1) Install Light Auth
npm -i @light-auth/nextjs2) Configure Light Auth
// file: "./lib/auth.ts"
import { Google, Github } from "arctic";
import { CreateLightAuth } from "@light-auth/nextjs";
const googleProvider = {
providerName: "google",
arctic: new Google(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, REDIRECT),
};
const githubProvider = {
providerName: "github",
arctic: new GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, REDIRECT)
};
export const { providers, handlers, signIn, signOut, getAuthSession, getUser } = CreateLightAuth({
providers: [googleProvider, githubProvider]3) Add Light Auth Handlers
// file: "./app/api/auth/[...lightauth].ts"
import { handlers } from "@/lib/auth";
export const { GET, POST } = handlers;4) Add login page
// file: "./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</button>
</form>
</div>
);
}5) Use Light Auth
// file: "./app/profile.tsx"
import { getAuthSession, signIn } 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>
<form
action={async () => {
"use server";
await signIn("google", "/profile");
}}
>
<button type="submit">login using a form action</button>
</form>
</div>
)}
</div>
);
}Contributing
Contributions are welcome! Please open issues or submit pull requests to help improve Light Auth.
License
This project is licensed under the MIT License.
