Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Lucia adapter for EdgeDB

NotificationsYou must be signed in to change notification settings

JitPackJoyride/lucia-adapter-edgedb

Repository files navigation

EdgeDB adapter for Lucia v2.

Lucia documentation

Changelog

Installation

bun add @jitpackjoyride/lucia-adapter-edgedb (recommended)npm install @jitpackjoyride/lucia-adapter-edgedbpnpm add @jitpackjoyride/lucia-adapter-edgedbyarn add @jitpackjoyride/lucia-adapter-edgedb

Usage

Do the usual EdgeDB setup, such asedgedb project init. Then, add this to your schema indbschema/default.esdl:

moduledefault {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 googlerequired key_id:str {constraintexclusive {errmessage:="UserKey: key_id violates exclusivity constraint"}}required user: User {ontargetdeletedeletesource;}hashed_password:str;indexon (.key_id);indexon (.user);}type UserSession {required user: User {ontargetdeletedeletesource;}required active_expires:int64;required idle_expires:int64;indexon (.user);}}

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

edgedb migration createedgedb migratebunx @edgedb/generate edgeql-js

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

Then, add this tosrc/app.d.ts:

// src/app.d.tsimporte,{$infer}from"../dbschema/edgeql-js";constuserSelectQuery=e.select(e.User,()=>({  ...e.User["*"],}));typeUserInDb=$infer<typeofuserSelectQuery>[number];typeUser=Omit<UserInDb,"id">;constsessionSelectQuery=e.select(e.UserSession,()=>({  ...e.UserSession["*"],}));typeSessionInDb=$infer<typeofsessionSelectQuery>[number];typeSession=Omit<SessionInDb,"id"|"active_expires"|"idle_expires">;/// <reference types="lucia" />declarenamespaceLucia{typeAuth=import("./auth/lucia").Auth;// NOTE: Keep this in sync with the database schema of UsertypeDatabaseUserAttributes=User;// NOTE: Keep this in sync with the database schema of UserSessiontypeDatabaseSessionAttributes=Session;}

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

// src/edgedb.tsimport*asedgedbfrom"edgedb";constclient=edgedb.createClient().withConfig({allow_user_specified_id:true,});exportdefaultclient;

Note theallow_user_specified_id option. This is required for allowing theid field to be set by the user or by Lucia. Read theGotchas section for more information.

Gotchas

Usingauth.setUser orauth.setSession

When calling eitherauth.setUser orauth.setSession, it is highly recommended to generate your own random uuid for theid field. You can do this withuuidv4 fromuuid orcrypto.randomUUID fromcrypto.

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.


[8]ページ先頭

©2009-2025 Movatter.jp