npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@light-auth/sveltekit

v0.3.5

Published

light auth framework for sveltekit, using arctic

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 | |-----------------------------------------------|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| | NextJS Next.js | light-auth-nextjs | Next.js Sample | | Astro Astro | light-auth-astro | Astro Sample | | Nuxt Nuxt | light-auth-nuxt | Nuxt Sample | | SvelteKit SvelteKit | light-auth-sveltekit | SvelteKit Sample | | Express Express | light-auth-express | Express Sample | | Tanstack Start 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/sveltekit 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/sveltekit

2) Configure Light Auth

// file: "./src/lib/server/auth.ts"

import { Google } from 'arctic';

import type { LightAuthProvider } from '@light-auth/core';
import { CreateLightAuth } from '@light-auth/sveltekit';
import { env } from '$env/dynamic/private';

const googleProvider: LightAuthProvider = {
	providerName: 'google',
	arctic: new Google(
      env.GOOGLE_CLIENT_ID, 
      env.GOOGLE_CLIENT_SECRET, 
      env.REDIRECT_URI),
	searchParams: new Map([['access_type', 'offline']])
};

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

4) Add Light Auth Handlers

Due to a bug in SvelteKit, the redirect response is not handled correctly.

Until this bug is fixed (#13816), we need to handle the redirect manually.

// file: "./src/routes/api/auth/[...lightauth]/+server.ts"

import { handlers } from '$lib/server/auth';
import { redirect, type RequestEvent } from '@sveltejs/kit';

const handlersSvelteKit = {
	GET: async (event?: RequestEvent) => {
		try {
			return await handlers.GET(event);
		} catch (error) {
			const redirectError = error as { status: number; location: string };
			if (redirectError && redirectError?.status === 302) redirect(redirectError.status, redirectError.location);
		}
	},
	POST: async (event?: RequestEvent) => {
		try {
			return await handlers.POST(event);
		} catch (error) {
			const redirectError = error as { status: number; location: string };
			if (redirectError && redirectError?.status === 302) redirect(redirectError.status, redirectError.location);
		}
	}
};

export const { GET, POST } = handlersSvelteKit;

5) Add login action

Due to a bug in SvelteKit, the redirect response is not handled correctly.

Until this bug is fixed (#13816), we need to handle the redirect manually.

// file: "./src/routes/login/+page.server.ts"

import { signIn, getAuthSession } from '$lib/server/auth';
import { redirect } from '@sveltejs/kit';
import type { Actions } from './$types';

export const actions = {
	default: async (event) => {
		try {
			const data = await event.request.formData();

			const providerName = data.get('providerName');
			const callbackUrl = data.get('callbackUrl');
			if (typeof providerName !== 'string') throw new Error('Invalid provider');
			if (typeof callbackUrl !== 'string') throw new Error('Invalid callback URL');

			await signIn(event, providerName, callbackUrl);
		} catch (error) {
			const r = error as { status: number; location: string };
			if (r?.status === 302) redirect(r.status, r.location);
		}
	}
} satisfies Actions;

6) Add login page

<!-- file: "./src/routes/login/+page.svelte" -->

<main>
    <div>
      <form method="POST">
        <input type="hidden" name="providerName" value="google" />
        <input type="hidden" name="callbackUrl" value="/" />
        <button type="submit">Login</button>
      </form>
    </div>
</main>

7) Use Light Auth in profile page

Server side:

// file: "./src/routes/+page.server.ts"

import { getAuthSession } from '$lib/server/auth';

export const load = async (event) => {
	const session = await getAuthSession(event);
	return { session };
};

Svelte page:

<!-- file: "./src/routes/+page.svelte" -->

<script lang="ts">
	let { data } = $props();
</script>

<template>
  <div>
    <h1>Profile</h1>

    <div>
  		{#if data.session}
        <div>
            <p>✅ You are logged in !</p>
            <h3>Session:</h3>
            <pre>{{JSON.stringify(data.session, null, 2)}}</pre>
        </div>
		  {:else}
        <p>⚠️ You are not logged in</p>
      {/if}
    </div>
  </div>
</template>

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.