-
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Upstash Redis Session adapter (#699)
Co-authored-by: pilcrowOnPaper <[email protected]>
- Loading branch information
1 parent
26f5240
commit e6cb093
Showing
19 changed files
with
285 additions
and
32 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,8 @@ | ||
--- | ||
package: "@lucia-auth/adapter-session-redis" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
--- | ||
|
||
|
||
Add Redis adapter for Upstash | ||
|
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
52 changes: 52 additions & 0 deletions
52
documentation-v2/content/main/2.database-adapters/upstash.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,52 @@ | ||
--- | ||
order: 0 | ||
title: "Upstash" | ||
description: "Learn how to use Upstas Redis with Lucia" | ||
--- | ||
|
||
Session adapter for [Upstash Redis](https://upstash.com) provided by the Redis session adapter package. This only handles sessions, and not users or keys. | ||
|
||
```ts | ||
import { upstash } from "@lucia-auth/adapter-session-redis"; | ||
``` | ||
|
||
```ts | ||
const upstash: ( | ||
upstashClient: Redis, | ||
prefixes?: { | ||
session: string; | ||
userSessions: string; | ||
} | ||
) => InitializeAdapter<SessionAdapter>; | ||
``` | ||
|
||
##### Parameters | ||
|
||
| name | type | optional | description | | ||
| --------------- | ------------------------ | :------: | ------------------------------------ | | ||
| `upstashClient` | `Redis` | | Serverless redis client for upstash. | | ||
| `prefixes` | `Record<string, string>` | ✓ | Key prefixes | | ||
|
||
### Key prefixes | ||
|
||
Key are defined as a combination of a prefix and an id so everything can be stored in a single Redis instance. By default, sessions are stored as `session:<session_id>` and user-sessions relationships are stored as `user_sessions:<user_id>`. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { lucia } from "lucia"; | ||
import { upstash } from "@lucia-auth/adapter-session-redis"; | ||
import { Redis } from "@upstash/redis"; | ||
|
||
const upstashClient = new Redis({ | ||
// ... | ||
}); | ||
|
||
const auth = lucia({ | ||
adapter: { | ||
user: userAdapter, // any normal adapter for storing users/keys | ||
session: upstash(upstashClient) | ||
} | ||
// ... | ||
}); | ||
``` |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
REDIS_PORT="" | ||
# for Redis adapter | ||
REDIS_PORT="your_redis_port" | ||
|
||
# for Upstash adapter | ||
URL="your_upstash_url" | ||
TOKEN="your_upstash_token" |
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 |
---|---|---|
@@ -1,25 +1,36 @@ | ||
# `@lucia-auth/adapter-session-redis` | ||
|
||
[Redis](https://redis.io) session adapter for Lucia | ||
|
||
**[Documentation](https://lucia-auth.com/database/redis)** | ||
Redis session adapters for Lucia | ||
|
||
**[Lucia documentation](https://lucia-auth.com)** | ||
|
||
**[Changelog](https://github.com/pilcrowOnPaper/lucia/blob/main/packages/session-adapter-redis/CHANGELOG.md)** | ||
|
||
## Included adapters | ||
|
||
- [Redis](https://redis.io) ([Documentation](https://v2.lucia-auth.com/database-adapters/redis)) | ||
- [Upstash](https://upstash.com) ([Documentation](https://v2.lucia-auth.com/database-adapters/upstash)) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install @lucia-auth/adapter-session-redis | ||
``` | ||
|
||
`[email protected]` recommended. | ||
|
||
## Testing | ||
|
||
Add a postgresql database url to `.env`. | ||
### Redis | ||
|
||
Add the port of a local Redis DB to `.env`. | ||
|
||
``` | ||
npm run test.redis | ||
``` | ||
|
||
### Upstash | ||
|
||
Add the `UPSTASH_REDIS_REST_URL` and the `UPSTASH_REDIS_REST_TOKEN` to `.env`. | ||
|
||
``` | ||
npm run test | ||
npm run test.upstash | ||
``` |
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
2 changes: 1 addition & 1 deletion
2
packages/adapter-session-redis/src/redis.ts → ...dapter-session-redis/src/drivers/redis.ts
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.