0.0.3 • Published 1 year ago

@gtramontina.com/elysia-authkit v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Elysia AuthKit

Elysia plugin to integrate with AuthKit.

!NOTE
This package is not affiliated with AuthKit or WorkOS. It currently only implements the flow described in the AuthKit Getting Started guide (hosted sign up and sign in forms).

Installation

bun add --exact @gtramontina.com/elysia-authkit

Usage

Follow the initial steps of the AuthKit documentation to get an account and keys setup.

import { authKit } from "@gtramontina.com/elysia-authkit";
import { WorkOS } from "@workos-inc/node";
import { Elysia } from "elysia";

new Elysia()
	.use(
		authKit({
			workos: new WorkOS(process.env.WORKOS_API_KEY),
			clientId: process.env.WORKOS_CLIENT_ID,
			jwtSecret: process.env.JWT_SECRET_KEY,
			redirectUri: "http://localhost:8080/callback",
		}),
	)
	.onError(({ code, error, set }) => {
		if (code === "UnauthorizedError") {
			set.redirect = "/login";
		}
	})
	.get("/", ({ user }) => {
		return `Hello, ${user.firstName ?? "world"}!`;
	})
	.listen(8080, () => {
		console.info("Listening on http://localhost:8080");
	});

Please feel free to explore the example for a more complete usage and the Options type for more details and options on how to customize the plugin for your needs.

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago