mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
fix: eslint errors, switch to using maps
This commit is contained in:
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user