- Notifications
You must be signed in to change notification settings - Fork1
Lucia adapter for EdgeDB
JitPackJoyride/lucia-adapter-edgedb
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
EdgeDB adapter for Lucia v2.
bun add @jitpackjoyride/lucia-adapter-edgedb (recommended)npm install @jitpackjoyride/lucia-adapter-edgedbpnpm add @jitpackjoyride/lucia-adapter-edgedbyarn add @jitpackjoyride/lucia-adapter-edgedbDo 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.
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.
Not yet implemented.
About
Lucia adapter for EdgeDB
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Contributors3
Uh oh!
There was an error while loading.Please reload this page.