mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-01 17:34:15 +03:00
chore: Do some minor cleanup
This commit is contained in:
@@ -2,11 +2,10 @@ import { z } from "zod/v4";
|
|||||||
import { RedisClient } from "bun";
|
import { RedisClient } from "bun";
|
||||||
import { subjects } from "../subjects.js";
|
import { subjects } from "../subjects.js";
|
||||||
import { issuer } from "@openauthjs/openauth";
|
import { issuer } from "@openauthjs/openauth";
|
||||||
import { RedisStorage } from "./src/storage.js";
|
|
||||||
import { Team } from "@nestri/core/team/index";
|
import { Team } from "@nestri/core/team/index";
|
||||||
|
import { RedisStorage } from "./src/storage.js";
|
||||||
import { CodeProvider } from "@openauthjs/openauth/provider/code";
|
import { CodeProvider } from "@openauthjs/openauth/provider/code";
|
||||||
|
|
||||||
//!TODO: Add an auth storage adapter, maybe redis or postgres
|
|
||||||
const storage = RedisStorage({
|
const storage = RedisStorage({
|
||||||
client: new RedisClient(process.env.REDIS_URL),
|
client: new RedisClient(process.env.REDIS_URL),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ export interface RedisStorageOptions {
|
|||||||
defaultTTL?: number;
|
defaultTTL?: number;
|
||||||
client: typeof RedisClient;
|
client: typeof RedisClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Cloudflare KV store.
|
* Creates a Redis DB store.
|
||||||
* @param options - The config for the adapter.
|
* @param options - The config for the adapter.
|
||||||
*/
|
*/
|
||||||
export function RedisStorage(options: RedisStorageOptions): StorageAdapter {
|
export function RedisStorage(options: RedisStorageOptions): StorageAdapter {
|
||||||
const { client } = options;
|
const { client } = options;
|
||||||
const prefix = "storage";
|
const prefix = "auth";
|
||||||
|
|
||||||
function createKey(key: string[]): string {
|
function createKey(key: string[]): string {
|
||||||
return `${prefix}:${joinKey(key)}`;
|
return `${prefix}:${joinKey(key)}`;
|
||||||
@@ -48,6 +49,7 @@ export function RedisStorage(options: RedisStorageOptions): StorageAdapter {
|
|||||||
const withoutPrefix = redisKey.slice(prefix.length + 1);
|
const withoutPrefix = redisKey.slice(prefix.length + 1);
|
||||||
return withoutPrefix.split(separator);
|
return withoutPrefix.split(separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async get(key: string[]) {
|
async get(key: string[]) {
|
||||||
const redisKey = createKey(key);
|
const redisKey = createKey(key);
|
||||||
@@ -80,9 +82,8 @@ export function RedisStorage(options: RedisStorageOptions): StorageAdapter {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async *scan(prefix: string[]) {
|
async *scan(prefix: string[]) {
|
||||||
const scanPattern = `${createKey(prefix)}${
|
const scanPattern = `${createKey(prefix)}${prefix.length ? separator : ""}*`;
|
||||||
prefix.length ? separator : ""
|
|
||||||
}*`;
|
|
||||||
let cursor = "0";
|
let cursor = "0";
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|||||||
Reference in New Issue
Block a user