added the route

This commit is contained in:
daniel31x13
2024-06-26 21:38:34 -04:00
parent 586074ef43
commit 239589eaed
10 changed files with 185 additions and 41 deletions
+23
View File
@@ -0,0 +1,23 @@
import type { NextApiRequest, NextApiResponse } from "next";
import verifyByCredentials from "@/lib/api/verifyByCredentials";
import createSession from "@/lib/api/controllers/session/createSession";
export default async function session(
req: NextApiRequest,
res: NextApiResponse
) {
const { username, password, sessionName } = req.body;
const user = await verifyByCredentials({ username, password });
if (!user)
return res.status(400).json({
response:
"Invalid credentials. You might need to reset your password if you're sure you already signed up with the current username/email.",
});
if (req.method === "POST") {
const token = await createSession(user.id, sessionName);
return res.status(token.status).json({ response: token.response });
}
}
+43 -38
View File
@@ -49,45 +49,50 @@ export default function AccessTokens() {
</button>
{tokens.length > 0 ? (
<>
<div className="divider my-0"></div>
<table className="table">
<thead>
<tr>
<th></th>
<th>{t("name")}</th>
<th>{t("created")}</th>
<th>{t("expires")}</th>
<th></th>
</tr>
</thead>
<tbody>
{tokens.map((token, i) => (
<React.Fragment key={i}>
<tr>
<th>{i + 1}</th>
<td>{token.name}</td>
<td>
{new Date(token.createdAt || "").toLocaleDateString()}
</td>
<td>
{new Date(token.expires || "").toLocaleDateString()}
</td>
<td>
<button
className="btn btn-sm btn-ghost btn-square hover:bg-red-500"
onClick={() => openRevokeModal(token as AccessToken)}
<table className="table mt-2 overflow-x-auto">
<thead>
<tr>
<th>{t("name")}</th>
<th>{t("created")}</th>
<th>{t("expires")}</th>
<th></th>
</tr>
</thead>
<tbody>
{tokens.map((token, i) => (
<React.Fragment key={i}>
<tr>
<td className={token.isSession ? "text-primary" : ""}>
{token.isSession ? (
<div
className="tooltip tooltip-right text-left"
data-tip="This is a permanent session"
>
<i className="bi-x text-lg"></i>
</button>
</td>
</tr>
</React.Fragment>
))}
</tbody>
</table>
</>
{token.name}
</div>
) : (
token.name
)}
</td>
<td>
{new Date(token.createdAt || "").toLocaleDateString()}
</td>
<td>
{new Date(token.expires || "").toLocaleDateString()}
</td>
<td>
<button
className="btn btn-sm btn-ghost btn-square hover:bg-red-500"
onClick={() => openRevokeModal(token as AccessToken)}
>
<i className="bi-x text-lg"></i>
</button>
</td>
</tr>
</React.Fragment>
))}
</tbody>
</table>
) : undefined}
</div>