-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pilcrowOnPaper <[email protected]> Co-authored-by: pilcrowOnPaper <[email protected]>
- Loading branch information
1 parent
b8c7332
commit 3e42405
Showing
17 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/adapter-sqlite" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
--- | ||
|
||
Add libSQL adapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
documentation-v2/content/main/2.database-adapters/libsql.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
menuTitle: "libSQL" | ||
title: "libSQL adapter" | ||
description: "Learn how to use libSQL with Lucia" | ||
--- | ||
|
||
Adapter for [libSQL](https://github.com/libsql/libsql) provided by the SQLite adapter package. | ||
|
||
```ts | ||
import { libSQL } from "@lucia-auth/adapter-sqlite"; | ||
``` | ||
|
||
```ts | ||
const libSQL: ( | ||
client: Client, | ||
tableNames: { | ||
user: string; | ||
key: string; | ||
session: string; | ||
} | ||
) => InitializeAdapter<Adapter>; | ||
``` | ||
|
||
##### Parameters | ||
|
||
Table names are automatically escaped. | ||
|
||
| name | type | description | | ||
| -------------------- | -------- | ------------------ | | ||
| `client` | `Client` | Database client | | ||
| `tableNames.user` | `string` | User table name | | ||
| `tableNames.key` | `string` | Key table name | | ||
| `tableNames.session` | `string` | Session table name | | ||
|
||
## Installation | ||
|
||
``` | ||
npm i @lucia-auth/adapter-sqlite | ||
pnpm add @lucia-auth/adapter-sqlite | ||
yarn add @lucia-auth/adapter-sqlite | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { lucia } from "lucia"; | ||
import { libsql } from "@lucia-auth/adapter-sqlite"; | ||
import { createClient } from "@libsql/client"; | ||
|
||
const db = createClient({ | ||
url: "file:test/main.db" | ||
}); | ||
|
||
const auth = lucia({ | ||
adapter: libsql(db, { | ||
user: "user", | ||
key: "user_key", | ||
session: "user_session" | ||
}) | ||
// ... | ||
}); | ||
``` | ||
|
||
## libSQL schema | ||
|
||
You can choose any table names, just make sure to define them in the adapter argument. | ||
|
||
### User table | ||
|
||
You can add additional columns to store user attributes. | ||
|
||
```sql | ||
CREATE TABLE user ( | ||
id VARCHAR(31) NOT NULL PRIMARY KEY | ||
); | ||
``` | ||
|
||
### Key table | ||
|
||
Make sure to update the foreign key statement if you change the user table name. | ||
|
||
```sql | ||
CREATE TABLE user_key ( | ||
id VARCHAR(255) NOT NULL PRIMARY KEY, | ||
user_id VARCHAR(15) NOT NULL, | ||
hashed_password VARCHAR(255), | ||
FOREIGN KEY (user_id) REFERENCES user(id) | ||
); | ||
``` | ||
|
||
### Session table | ||
|
||
You can add additional columns to store session attributes. Make sure to update the foreign key statement if you change the user table name. | ||
|
||
```sql | ||
CREATE TABLE user_session ( | ||
id VARCHAR(127) NOT NULL PRIMARY KEY, | ||
user_id VARCHAR(15) NOT NULL, | ||
active_expires BIGINT NOT NULL, | ||
idle_expires BIGINT NOT NULL, | ||
FOREIGN KEY (user_id) REFERENCES user(id) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.