This commit is contained in:
Atridad Lahiji 2023-06-29 16:52:23 -06:00 committed by atridadl
parent cfe7e387f0
commit cc7d6b01ae
No known key found for this signature in database
4 changed files with 44 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "sprintpadawan",
"version": "1.2.1",
"version": "1.2.2",
"description": "Plan. Sprint. Repeat.",
"private": true,
"scripts": {

View file

@ -106,6 +106,14 @@ const AdminBody: React.FC = () => {
},
});
const clearSessionsByUserMutation = api.session.deleteAllByUserId.useMutation(
{
onSuccess: async () => {
await refetchData();
},
}
);
const clearSessionsMutation = api.session.deleteAll.useMutation({
onSuccess: async () => {
await refetchData();
@ -122,8 +130,12 @@ const AdminBody: React.FC = () => {
await deleteUserMutation.mutateAsync({ userId });
};
const clearSessionsHandler = async (userId: string) => {
await clearSessionsMutation.mutateAsync({ userId });
const clearSessionsByUserHandler = async (userId: string) => {
await clearSessionsByUserMutation.mutateAsync({ userId });
};
const clearSessionsHandler = async () => {
await clearSessionsMutation.mutateAsync();
};
const setUserRoleHandler = async (userId: string, role: Role) => {
@ -184,9 +196,21 @@ const AdminBody: React.FC = () => {
votesCountFetching ? (
<span className="loading loading-dots loading-lg"></span>
) : (
<button className="btn btn-primary" onClick={() => void refetchData()}>
Re-fetch
</button>
<>
<button
className="btn btn-primary"
onClick={() => void refetchData()}
>
Re-fetch
</button>
<button
className="btn btn-primary"
onClick={() => void clearSessionsHandler()}
>
Delete All Sessions
</button>
</>
)}
<div className="card max-w-[80vw] bg-neutral shadow-xl m-4">
@ -258,7 +282,9 @@ const AdminBody: React.FC = () => {
</button>
<button
className="m-2"
onClick={() => void clearSessionsHandler(user.id)}
onClick={() =>
void clearSessionsByUserHandler(user.id)
}
>
<AiOutlineClear className="text-xl inline-block hover:text-warning" />
</button>

View file

@ -4,7 +4,7 @@ import { env } from "~/env.mjs";
import { redis } from "~/server/redis";
export const sessionRouter = createTRPCRouter({
deleteAll: protectedProcedure
deleteAllByUserId: protectedProcedure
.input(
z.object({
userId: z.string(),
@ -23,4 +23,13 @@ export const sessionRouter = createTRPCRouter({
return !!sessions;
}),
deleteAll: protectedProcedure.mutation(async ({ ctx, input }) => {
const sessions = await ctx.prisma.session.deleteMany();
if (!!sessions) {
await redis.del(`${env.APP_ENV}_kv_userlist_admin`);
}
return !!sessions;
}),
});

View file

@ -1,9 +1,6 @@
import { Redis } from "@upstash/redis";
import { env } from "~/env.mjs";
import https from "https";
export const redis = new Redis({
url: env.UPSTASH_REDIS_REST_URL,
token: env.UPSTASH_REDIS_REST_TOKEN,
export const redis = Redis.fromEnv({
agent: new https.Agent({ keepAlive: true }),
});