Merged in limit5SessionsUser (pull request #161)
Implemented limit 5 sessions per User Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import clsx from "clsx";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { BsArrowDown, BsArrowUp } from "react-icons/bs";
|
||||
import Button from "../Low/Button";
|
||||
|
||||
|
||||
@@ -48,4 +48,9 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
await db.collection("sessions").updateOne({ id: session.id }, { $set: session }, { upsert: true });
|
||||
|
||||
res.status(200).json({ ok: true });
|
||||
const sessions = await db.collection("sessions").find<Session>({ user: session.user }, { projection: { id: 1 } }).sort({ date: 1 }).toArray();
|
||||
// Delete old sessions
|
||||
if (sessions.length > 5) {
|
||||
await db.collection("sessions").deleteOne({ id: { $in: sessions.slice(0, sessions.length - 5).map(x => x.id) } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user