Get Started with Light-Auth

Learn how to quickly integrate Light-Auth into your application.

0

Prerequisites

What you need before getting started

Before you begin, make sure you have the following:

  • A decent / recent version of Node.js
  • npm or yarn package manager
  • A provider authentication client ID and secret
1

Installation

Install the Light-Auth package

Install the Light-Auth package using your preferred package manager:

npm install light-auth-nextjs
2

Initialization

Initialize the Light-Auth package

Set up Light-Auth in your application

3

handlers

Initialize the Light-Auth handlers / middleware

Set up Light-Auth handlers / middleware in your application

./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]
});