Skip to content

Commit

Permalink
fix: tweak auth guard
Browse files Browse the repository at this point in the history
  • Loading branch information
betich committed Aug 22, 2023
1 parent 62228f7 commit 508c467
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,25 @@ export const AuthProvider = ({
// should not have user
case '/':
break;
case '/event':
case '/event/create':
if (!user) {
router.push('/login');
}
break;

// event with id

case '/login':
if (user) {
router.push('/');
}
break;
// should have user
default:
if (!user) {
router.push('/login');
}
// if (!user) {
// router.push('/login');
// }
break;
}
}, [user, router]);
Expand Down
8 changes: 8 additions & 0 deletions src/pages/event/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import useScheduleSlot from '@/hooks/useScheduleSlot';
import { useRouter } from 'next/router';

import QrCode from 'react-qr-code';
import { useAuth } from '@/lib/auth';

export function getServerSideProps({ params }: { params: { id: string } }) {
return {
Expand All @@ -51,11 +52,18 @@ export default function View({
const { scheduleSlots, currentSlot, nextSlot, currentTime } =
useScheduleSlot(id);
const router = useRouter();
const { user } = useAuth();

useEffect(() => {
runOneSignal();
}, []);

useEffect(() => {
if (!user) {
router.push('/login');
}
}, [user, router]);

const handleOnDeleteTaskData = (data: ScheduleSlot) => {
deleteTask(id, scheduleSlots, data);
};
Expand Down

0 comments on commit 508c467

Please sign in to comment.