From c7d681b3a3deb5cc4b31cf2f3fdd2a0662011d31 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 23 Oct 2023 12:55:28 +0300 Subject: [PATCH] destroying session when user cannot be found --- app/modules/tag/service.server.ts | 2 +- app/routes/_index.tsx | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/modules/tag/service.server.ts b/app/modules/tag/service.server.ts index b210d5e08..86d2f7b6c 100644 --- a/app/modules/tag/service.server.ts +++ b/app/modules/tag/service.server.ts @@ -22,7 +22,7 @@ export async function getTags({ const take = perPage >= 1 ? perPage : 8; // min 1 and max 25 per page /** Default value of where. Takes the items belonging to current user */ - let where: Prisma.CategoryWhereInput = { userId }; + let where: Prisma.TagWhereInput = { userId }; /** If the search string exists, add it to the where object */ if (search) { diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index c22f66a25..d6795185f 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "@remix-run/node"; import { redirect } from "@remix-run/node"; -import { getAuthSession } from "~/modules/auth"; +import { destroyAuthSession, getAuthSession } from "~/modules/auth"; import { getUserByEmail } from "~/modules/user"; export const loader = async ({ request }: LoaderFunctionArgs) => { @@ -18,5 +18,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { if (user) { return redirect(user.onboarded ? "/assets" : "onboarding"); } - return redirect("login"); + /** Not finding user for the current session is sus + * So we just destroy the session and redirect to / + */ + return destroyAuthSession(request); };