ENCOA-279

This commit is contained in:
Tiago Ribeiro
2024-12-12 15:06:00 +00:00
parent 3e74827c47
commit 240e36f15a
11 changed files with 71 additions and 73 deletions

View File

@@ -64,7 +64,7 @@ export default function Reset({code, mode, continueUrl}: {code: string; mode: st
});
setTimeout(() => {
router.push("/");
}, 1000);
}, 500);
return;
}

View File

@@ -73,9 +73,8 @@ async function registerIndividual(req: NextApiRequest, res: NextApiResponse) {
...(passport_id ? { demographicInformation: { passport_id } } : {}),
registrationDate: new Date().toISOString(),
status: code ? "active" : "paymentDue",
// apparently there's an issue with the verification email system
// therefore we will skip this requirement for now
isVerified: true,
entities: [],
isVerified: !!codeDoc,
};
await db.collection("users").insertOne(user);

View File

@@ -47,7 +47,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer"])) return redirect("/")

View File

@@ -46,7 +46,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "corporate"])) return redirect("/")

View File

@@ -47,7 +47,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer"])) return redirect("/")

View File

@@ -6,7 +6,7 @@ import {withIronSessionSsr} from "iron-session/next";
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
return redirect(`/dashboard/${user.type}`)
}, sessionOptions);

View File

@@ -52,7 +52,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "mastercorporate"]))
return redirect("/")

View File

@@ -51,7 +51,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "student"]))
return redirect("/")
@@ -90,11 +90,13 @@ export default function Dashboard({user, entities, assignments, stats, invites,
})
if (assignmentExams.every((x) => !!x)) {
dispatch({type: "INIT_EXAM", payload: {
dispatch({
type: "INIT_EXAM", payload: {
exams: assignmentExams.sort(sortByModule),
modules: mapBy(assignmentExams.sort(sortByModule), 'module'),
assignment
}})
}
})
router.push("/exam");
}

View File

@@ -39,7 +39,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "teacher"]))
return redirect("/")

View File

@@ -6,7 +6,7 @@ import {withIronSessionSsr} from "iron-session/next";
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user || !user.isVerified) return redirect("/login")
return redirect(`/dashboard/${user.type}`)
}, sessionOptions);

View File

@@ -23,7 +23,7 @@ const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString()
const user = await requestUser(req, res)
if (user) return redirect(destination)
if (user && user.isVerified) return redirect(destination)
return {
props: { user: null, destination },
@@ -39,13 +39,10 @@ export default function Login({ destination = "/" }: { destination?: string }) {
const router = useRouter();
const isOfficialExamLogin = useMemo(() => destination.startsWith("/official-exam"), [destination])
const { user, mutateUser } = useUser({
redirectTo: destination,
redirectIfFound: true,
});
const { user, mutateUser } = useUser();
useEffect(() => {
if (user) router.push(destination);
if (user && user.isVerified) router.push(destination);
}, [router, user, destination]);
const forgotPassword = () => {
@@ -173,7 +170,7 @@ export default function Login({ destination = "/" }: { destination?: string }) {
</span>
</>
)}
{/* {user && !user.isVerified && <EmailVerification user={user} isLoading={isLoading} setIsLoading={setIsLoading} />} */}
{user && !user.isVerified && <EmailVerification user={user} isLoading={isLoading} setIsLoading={setIsLoading} />}
</section>
</main>
</>