diff --git a/packages/function/src/auth/index.ts b/packages/function/src/auth/index.ts index 0a3d2f05..4c669454 100644 --- a/packages/function/src/auth/index.ts +++ b/packages/function/src/auth/index.ts @@ -2,11 +2,10 @@ import { z } from "zod/v4"; import { RedisClient } from "bun"; import { subjects } from "../subjects.js"; import { issuer } from "@openauthjs/openauth"; -import { RedisStorage } from "./src/storage.js"; import { Team } from "@nestri/core/team/index"; +import { RedisStorage } from "./src/storage.js"; import { CodeProvider } from "@openauthjs/openauth/provider/code"; -//!TODO: Add an auth storage adapter, maybe redis or postgres const storage = RedisStorage({ client: new RedisClient(process.env.REDIS_URL), }); diff --git a/packages/function/src/auth/src/storage.ts b/packages/function/src/auth/src/storage.ts index 19308e38..39f4c8bf 100644 --- a/packages/function/src/auth/src/storage.ts +++ b/packages/function/src/auth/src/storage.ts @@ -32,13 +32,14 @@ export interface RedisStorageOptions { defaultTTL?: number; client: typeof RedisClient; } + /** - * Creates a Cloudflare KV store. + * Creates a Redis DB store. * @param options - The config for the adapter. */ export function RedisStorage(options: RedisStorageOptions): StorageAdapter { const { client } = options; - const prefix = "storage"; + const prefix = "auth"; function createKey(key: string[]): string { return `${prefix}:${joinKey(key)}`; @@ -48,6 +49,7 @@ export function RedisStorage(options: RedisStorageOptions): StorageAdapter { const withoutPrefix = redisKey.slice(prefix.length + 1); return withoutPrefix.split(separator); } + return { async get(key: string[]) { const redisKey = createKey(key); @@ -80,9 +82,8 @@ export function RedisStorage(options: RedisStorageOptions): StorageAdapter { }, async *scan(prefix: string[]) { - const scanPattern = `${createKey(prefix)}${ - prefix.length ? separator : "" - }*`; + const scanPattern = `${createKey(prefix)}${prefix.length ? separator : ""}*`; + let cursor = "0"; do {