Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JitPackJoyride/lucia-adapter-edgedb
Lucia adapter for EdgeDB
https://github.com/JitPackJoyride/lucia-adapter-edgedb
adapter edgedb lucia lucia-auth
Last synced: 2 months ago
JSON representation
Lucia adapter for EdgeDB
- Host: GitHub
- URL: https://github.com/JitPackJoyride/lucia-adapter-edgedb
- Owner: JitPackJoyride
- Created: 2023-09-09T12:12:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-09T06:39:28.000Z (about 1 year ago)
- Last Synced: 2024-10-06T02:17:55.811Z (3 months ago)
- Topics: adapter, edgedb, lucia, lucia-auth
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@jitpackjoyride/lucia-adapter-edgedb
- Size: 96.7 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-edgedb - EdgeDB Lucia-Auth Adapter - An adapter for [Lucia-Auth](https://lucia-auth.com/) that utilizes EdgeDB as storage for your authentication and user data. (Integrations)
README
# `@jitpackjoyride/lucia-adapter-edgedb`
[EdgeDB](https://www.edgedb.com/) adapter for Lucia v2.
**[Lucia documentation](https://lucia-auth.com)**
**[Changelog](https://github.com/JitPackJoyride/lucia-adapter-edgedb/blob/main/CHANGELOG.md)**
## 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`:
```esdl
module default {
type User {
link auth_keys := . ({
...e.User["*"],
}));
type UserInDb = $infer[number];
type User = Omit;const sessionSelectQuery = e.select(e.UserSession, () => ({
...e.UserSession["*"],
}));
type SessionInDb = $infer[number];
type Session = Omit;///
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:
```typescript
// 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](#using-authsetuser-or-authsetsession) 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:
```typescript
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.