Skip to content

Commit

Permalink
destroying session when user cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko committed Oct 23, 2023
1 parent c8dad6f commit c7d681b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/modules/tag/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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);
};

0 comments on commit c7d681b

Please sign in to comment.