fix: eslint errors, switch to using maps

This commit is contained in:
Huskydog9988
2025-04-15 20:04:45 -04:00
parent e362f732e7
commit 8f429e1e56
21 changed files with 158 additions and 159 deletions

View File

@ -1,29 +1,29 @@
import type { Session, SessionProvider } from "./types";
export default function createMemorySessionHandler() {
const sessions: { [key: string]: Session } = {};
const sessions = new Map<string, Session>();
const memoryProvider: SessionProvider = {
async setSession(token, data) {
sessions[token] = data;
sessions.set(token, data);
return true;
},
async getSession<T extends Session>(token: string): Promise<T | undefined> {
const session = sessions[token];
const session = sessions.get(token);
return session ? (session as T) : undefined; // Ensure undefined is returned if session is not found
},
async updateSession(token, data) {
return this.setSession(token, data);
},
async removeSession(token) {
delete sessions[token];
sessions.delete(token);
return true;
},
async cleanupSessions() {
const now = new Date();
for (const token in sessions) {
for (const [token, session] of sessions) {
// if expires at time is before now, the session is expired
if (sessions[token].expiresAt < now) await this.removeSession(token);
if (session.expiresAt < now) await this.removeSession(token);
}
},
};