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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jitpackjoyride/lucia-adapter-edgedb

v0.3.0

Published

Lucia adapter for EdgeDB

Downloads

12

Readme

@jitpackjoyride/lucia-adapter-edgedb

EdgeDB adapter for Lucia v2.

Lucia documentation

Changelog

Installation

bun add @jitpackjoyride/lucia-adapter-edgedb (recommended)
npm install @jitpackjoyride/lucia-adapter-edgedb
pnpm add @jitpackjoyride/lucia-adapter-edgedb
yarn add @jitpackjoyride/lucia-adapter-edgedb

Usage

Do the usual EdgeDB setup, such as edgedb project init. Then, add this to your schema in dbschema/default.esdl:

module default {
	type User {
		link auth_keys := .<user[is UserKey];
		link auth_sessions := .<user[is UserSession];

		# put your own fields here
	}

	type UserKey {
		# key_id is the combination of providerKeyId and providerUserId
		# providerKeyId is your own custom id for the provider such as "google", "github", "email", etc.
		# providerUserId is the id returned by the provider such as "1234567890" for google
		required key_id: str {
			constraint exclusive {
				errmessage := "UserKey: key_id violates exclusivity constraint"
			}
		}
  		required user: User {
			on target delete delete source;
		}
		hashed_password: str;

		index on (.key_id);
		index on (.user);
	}

	type UserSession {
  		required user: User {
			on target delete delete source;
		}
  		required active_expires: int64;
  		required idle_expires: int64;

		index on (.user);
	}
}

Run the following commands to create a migration and generate the typescript types:

edgedb migration create
edgedb migrate
bunx @edgedb/generate edgeql-js

(If you're using npm, you can use npx @edgedb/generate edgeql-js)

Then, add this to src/app.d.ts:

// src/app.d.ts
import e, { $infer } from "../dbschema/edgeql-js";
const userSelectQuery = e.select(e.User, () => ({
  ...e.User["*"],
}));
type UserInDb = $infer<typeof userSelectQuery>[number];
type User = Omit<UserInDb, "id">;

const sessionSelectQuery = e.select(e.UserSession, () => ({
  ...e.UserSession["*"],
}));
type SessionInDb = $infer<typeof sessionSelectQuery>[number];
type Session = Omit<SessionInDb, "id" | "active_expires" | "idle_expires">;

/// <reference types="lucia" />
declare namespace Lucia {
  type Auth = import("./auth/lucia").Auth;
  // NOTE: Keep this in sync with the database schema of User
  type DatabaseUserAttributes = User;
  // NOTE: Keep this in sync with the database schema of UserSession
  type DatabaseSessionAttributes = Session;
}

When you're initialising the EdgeDB client, you need to do something like this:

// src/edgedb.ts
import * as edgedb from "edgedb";

const client = edgedb.createClient().withConfig({
  allow_user_specified_id: true,
});

export default client;

Note the allow_user_specified_id option. This is required for allowing the id field to be set by the user or by Lucia. Read the Gotchas section for more information.

Gotchas

Using auth.setUser or auth.setSession

When calling either auth.setUser or auth.setSession, it is highly recommended to generate your own random uuid for the id field. You can do this with uuidv4 from uuid or crypto.randomUUID from crypto.

Example:

auth.setUser({
  userId: crypto.randomUUID(),
  // ... other fields
});

This is because Lucia's default id generator is random strings, but EdgeDB uses uuids. If you don't pass your own uuid, then the id will be a random string, which will make it hard to query the database.

Testing

Not yet implemented.