Skip to content

Commit

Permalink
feat: Add redirect to login page (#201)
Browse files Browse the repository at this point in the history
In the useEffect hook, implement logic to check if the user session is active using the ory.toSession() function. If the session is active, redirect the user to the login page.

Co-authored-by: Marluan Espiritusanto <[email protected]>
  • Loading branch information
JE1999 and marluanespiritusanto authored May 9, 2024
1 parent 59f9e42 commit 49a4877
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/[lang]/identification/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useReCaptcha } from 'next-recaptcha-v3';
import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import * as Sentry from '@sentry/nextjs';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import Link from 'next/link';
import { z } from 'zod';

Expand All @@ -25,19 +25,33 @@ import { CustomTextMask } from '@/components/CustomTextMask';
import { useSnackAlert } from '@/components/elements/alert';
import { ButtonApp } from '@/components/elements/button';
import { Validations } from '@/common/helpers';
import { ory } from '@/common/lib/ory';
import theme from '@/components/themes/theme';
import { useLanguage } from '../provider';

type CedulaForm = z.infer<ReturnType<typeof createCedulaSchema>>;

export function Form() {
const { AlertError, AlertWarning } = useSnackAlert();
const [loading, setLoading] = useState(false);
const [loading, setLoading] = useState(true);
const { executeRecaptcha } = useReCaptcha();
const router = useRouter();

const { intl } = useLanguage();

useEffect(() => {
ory
.toSession()
.then(({ data }) => {
if (data.active) {
return router.push('https://mi.cuentaunica.gob.do/ui/login');
} else {
setLoading(false);
}
})
.catch(() => setLoading(false));
}, []);

const {
handleSubmit,
formState: { errors },
Expand Down

0 comments on commit 49a4877

Please sign in to comment.