Files
homarr/packages/integrations/src/base/session-store.ts
Meier Lukas 3804d530ec feat(pihole): add support for v6 (#2448)
* feat(pihole): add support for v6

* fix: add session-store to keep using same session for pi-hole requests

* chore: address pull request feedback

* fix: import issue

* fix: other import errors
2025-03-04 21:17:35 +01:00

30 lines
1.0 KiB
TypeScript

import { decryptSecret, encryptSecret } from "@homarr/common/server";
import { logger } from "@homarr/log";
import { createGetSetChannel } from "@homarr/redis";
const localLogger = logger.child({ module: "SessionStore" });
export const createSessionStore = (integration: { id: string }) => {
const channelName = `session-store:${integration.id}`;
const channel = createGetSetChannel<`${string}.${string}`>(channelName);
return {
async getAsync() {
localLogger.debug("Getting session from store", { store: channelName });
const value = await channel.getAsync();
if (!value) return null;
return decryptSecret(value);
},
async setAsync(value: string) {
localLogger.debug("Updating session in store", { store: channelName });
await channel.setAsync(encryptSecret(value));
},
async clearAsync() {
localLogger.debug("Cleared session in store", { store: channelName });
await channel.removeAsync();
},
};
};
export type SessionStore = ReturnType<typeof createSessionStore>;