Skip to content

Commit

Permalink
feat: Add redirect to login page
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.
  • Loading branch information
JE1999 committed May 9, 2024
1 parent 90d8872 commit c7cba81
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 c7cba81

Please sign in to comment.