Skip to content

Commit

Permalink
add:auth check loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Kosei805 committed Nov 13, 2024
1 parent a6caf3b commit ffcf996
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion frontend/app/routes/home.cart/route.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ActionFunctionArgs, redirect } from '@remix-run/cloudflare';
import {
ActionFunctionArgs,
LoaderFunctionArgs,
redirect,
} from '@remix-run/cloudflare';
import { useSubmit } from '@remix-run/react';
import { upsertLoans } from 'client/client';
import { UpsertLoansBodyItem } from 'client/client.schemas';
Expand All @@ -11,6 +15,18 @@ import type { CartProps } from '~/stores/cartAtom';
import { removeBooksFromCart } from '~/utils/cart';
import { errorNotification } from '~/utils/notification';

export const loader = async ({ request }: LoaderFunctionArgs) => {
const session = await getSession(request.headers.get('Cookie'));
if (!session) {
return redirect('/login', {
headers: {
'Set-Cookie': await commitSession(session),
},
});
}
return null;
};

export const action = async ({ request }: ActionFunctionArgs) => {
const session = await getSession(request.headers.get('Cookie'));

Expand Down

0 comments on commit ffcf996

Please sign in to comment.