Skip to content

Commit

Permalink
Merge pull request #78 from cs3216-a3-group-4/seeleng/fix-onboarding
Browse files Browse the repository at this point in the history
fix: onboarding
  • Loading branch information
seelengxd authored Sep 25, 2024
2 parents 56d21f9 + ad2d7ac commit 9587775
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion frontend/app/(authenticated)/onboarding/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function Onboarding() {
const { data: categories, isLoading } = useQuery(getCategories());
const [categoryIds, setCategoryIds] = useState<number[]>([]);
const user = useUserStore((state) => state.user);
const setLoggedIn = useUserStore((state) => state.setLoggedIn);

const toggleCategory = (id: number) => {
if (!categoryIds.includes(id)) {
Expand All @@ -33,7 +34,8 @@ export default function Onboarding() {
updateProfileMutation.mutate(
{ categoryIds },
{
onSuccess: () => {
onSuccess: (data) => {
setLoggedIn(data.data!);
router.push("/");
},
},
Expand Down
16 changes: 9 additions & 7 deletions frontend/app/(authenticated)/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ export default function RedirectIfNotAuthenticated({
children,
}: Readonly<{ children: React.ReactNode }>) {
const router = useRouter();
const { status } = useQuery(getUserProfile());
const { fetchStatus } = useQuery(getUserProfile());

const isLoggedIn = useUserStore((state) => state.isLoggedIn);
const user = useUserStore((state) => state.user);
console.log({ isLoggedIn, status });

if (!isLoggedIn && !status) {
router.push("/login");
}
if (isLoggedIn && !user!.categories.length) {
router.push("/onboarding");
if (fetchStatus !== "fetching") {
if (!isLoggedIn) {
router.push("/login");
}
console.log("fetching", user);
if (isLoggedIn && !user!.categories.length) {
router.push("/onboarding");
}
}

return <Suspense>{children}</Suspense>;
Expand Down

0 comments on commit 9587775

Please sign in to comment.