Skip to content

Commit

Permalink
♻️ save session
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmnqdds committed Feb 13, 2024
1 parent 9893ea5 commit 209d9a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
4 changes: 3 additions & 1 deletion components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const LoginForm = () => {
});
};

return (
return profile ? (
<Button onClick={() => router.push("/dashboard")}>Next</Button>
) : (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2 mt-10">
<div className="flex flex-row items-center justify-center gap-2">
Expand Down
4 changes: 2 additions & 2 deletions components/ProfileDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export default function ProfileDropdown() {
onClick={async () => {
const res = await ImaluumLogout();
if (res.success) {
sessionStorage.clear();
localStorage.clear();
queryCache.clear();
toast.success("Logged out successfully.");
router.replace("/");
router.push("/");
}
}}
>
Expand Down
14 changes: 8 additions & 6 deletions context/ImaluumProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ import Image from "next/image";

const ImaluumProvider = ({ children }: { children: React.ReactNode }) => {
const { profile, setProfile } = useProfile();
const { setResult } = useResult();
const { setSchedule } = useSchedule();
const { result, setResult } = useResult();
const { schedule, setSchedule } = useSchedule();

const profileData = useQuery({
queryKey: ["profile"],
queryFn: async () => {
const data = await GetUserProfile(profile.matricNo as string);
if (data.success) {
setProfile(data.data);
const password = profile.password;
setProfile({ ...data.data, password });
return data.data;
}
},
retry: 3,
enabled: !profile.imageURL,
});

const resultData = useQuery({
Expand All @@ -37,6 +39,7 @@ const ImaluumProvider = ({ children }: { children: React.ReactNode }) => {
}
},
retry: 3,
enabled: !result,
});

const scheduleData = useQuery({
Expand All @@ -49,11 +52,10 @@ const ImaluumProvider = ({ children }: { children: React.ReactNode }) => {
}
},
retry: 3,
enabled: !schedule,
});

return profileData.isSuccess &&
resultData.isSuccess &&
scheduleData.isSuccess ? (
return profile && result && schedule ? (
<>{children}</>
) : (
<div className="w-full h-screen bg-background flex items-center justify-center">
Expand Down
18 changes: 0 additions & 18 deletions middleware.ts

This file was deleted.

0 comments on commit 209d9a8

Please sign in to comment.