0.0.10 • Published 5 months ago

guardbox v0.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Guardbox

Guardbox is an easy and modern authentication library.

Features

  • Easy - Authentication can be implemented without the need for specialized knowledge
  • Framework Independent - Guardbox can be used in any JavaScript/TypeScript project
  • Adapter - Abstraction of user and session management and greater flexibility in managing data
  • Provider - Custom providers can be implemented to support any authentication method
  • Acount Linking - Automatically link accounts with the same email
  • One Time Password - Easily implement email address verification, etc.

Quick Start

bun add guardbox    # npm install guardbox
import { Guardbox } from 'guardbox';
import { MemorySessionAdapter, MemoryUserAdapter } from 'guardbox/adapters/memory';
import { GoogleProvider } from 'guardbox/providers/google';

const userAdapter = new MemoryUserAdapter();
const sessionAdapter = new MemorySessionAdapter();

const googleAuth = new GoogleProvider({
    clientId: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    redirectUrl: 'http://localhost:3000/auth/google/callback',
});

// in request handler
const auth = new Guardbox({
    appName: 'guardbox',
    adapter: {
        user: userAdapter,
        session: sessionAdapter,
    },
    cookies: {
        get: (key) => {
            return getCookie(req, key);
        },
        set: (key, value, options) => {
            setCookie(res, key, value, options);
        },
        delete: (key, options) => {
            deleteCookie(res, key, options);
        },
    },
});

// sign in
const signInUrl = googleAuth.getSignInUrl(auth);
redirect(signInUrl);

// callback
const code = getQuery(req, 'code');
const state = getQuery(req, 'state');
const success = await googleAuth.authenticate(auth, code, state);

// sign out
await auth.signOut();
0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago