Skip to content

Commit

Permalink
feat: redirect user to login when registering an existing account. (#263
Browse files Browse the repository at this point in the history
)

feat: redirect user to login when registering an existing account.
  • Loading branch information
JeffreyArt1 authored Oct 10, 2024
2 parents ba6590a + 576a5d5 commit d10bec3
Show file tree
Hide file tree
Showing 9 changed files with 2,325 additions and 2,017 deletions.
51 changes: 29 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cuenta-unica-registry",
"description": "Portal de registro de Cuenta Única",
"version": "v1.5.2",
"version": "v1.5.3",
"private": false,
"author": "OGTIC",
"license": "MIT",
Expand Down Expand Up @@ -35,58 +35,65 @@
}
},
"dependencies": {
"@aws-amplify/adapter-nextjs": "^1.2.17",
"@aws-amplify/ui-react": "^6.2.1",
"@aws-amplify/ui-react-liveness": "^3.1.5",
"@aws-sdk/client-rekognition": "^3.645.0",
"@aws-amplify/adapter-nextjs": "^1.2.21",
"@aws-amplify/ui-react": "^6.5.3",
"@aws-amplify/ui-react-liveness": "^3.1.13",
"@aws-sdk/client-rekognition": "^3.668.0",
"@emotion/cache": "^11.13.1",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@formatjs/intl-localematcher": "^0.5.4",
"@hookform/resolvers": "^3.9.0",
"@mui/icons-material": "^5.16.7",
"@mui/material": "^5.16.7",
"@next/third-parties": "^14.2.8",
"@ory/client": "^1.14.5",
"@next/third-parties": "^14.2.15",
"@ory/client": "^1.15.6",
"@ory/integrations": "^1.2.1",
"@sentry/nextjs": "^8.28.0",
"aws-amplify": "^6.6.0",
"@sentry/nextjs": "^8.33.1",
"@tensorflow/tfjs-backend-webgl": "^4.21.0",
"@tensorflow/tfjs-converter": "^4.21.0",
"@tensorflow/tfjs-core": "4.21.0",
"aws-amplify": "^6.6.4",
"check-password-strength": "^2.0.10",
"hibp": "^14.1.2",
"negotiator": "^0.6.3",
"next": "^14.2.8",
"next": "^14.2.15",
"next-recaptcha-v3": "^1.4.1",
"react": "^18.3.1",
"react-gtm-module": "^2.0.11",
"react-hook-form": "7.53.0",
"react-imask": "^7.6.1",
"typescript": "^5.5.4",
"typescript": "^5.6.3",
"zod": "^3.23.8"
},
"devDependencies": {
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@testing-library/react": "^16.0.1",
"@types/cookie": "^0.6.0",
"@types/negotiator": "^0.6.3",
"@types/node": "^20.16.5",
"@types/react": "^18.3.5",
"@types/node": "^20.16.11",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@types/react-google-recaptcha": "^2.1.9",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.3.1",
"@vitejs/plugin-react": "^4.3.2",
"aws-crt": "^1.22.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.8",
"eslint": "^8.57.1",
"eslint-config-next": "^14.2.15",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.5",
"jsdom": "^25.0.0",
"husky": "^9.1.6",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"vitest": "^2.0.5"
"vitest": "^2.1.2"
},
"peerDependencies": {
"@aws-sdk/client-sso-oidc": "^3.668.0",
"@aws-sdk/client-sts": "^3.668.0"
}
}
4,169 changes: 2,176 additions & 1,993 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/actions/iam.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ async function findAccountInBackoffice(cedula: string) {
const url = new URL('v1/accounts', process.env.BACKOFFICE_API_URL);
url.searchParams.append('term', cedula);

const resp = await fetch(url, withCredentials());
const resp = await fetch(url, withCredentials()).catch((e) => ({
ok: false,
json: () => Promise.resolve(e.cause),
}));

if (resp.ok) {
return resp
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/identification/identify.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function identifyAccount(
const { exists } = await findIamCitizen(cedula);

if (exists) {
return { message: 'errors.cedula.exists' };
return redirect(`redirection?cedula=${cedula}`);
}

const citizen = await findCitizen(cedula).catch(() => null);
Expand Down
31 changes: 31 additions & 0 deletions src/app/[lang]/redirection/counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import React from 'react';
import { useRouter } from 'next/navigation';

import { LOGIN_URL } from '@/common';
import { useLanguage } from '../provider';

export function Counter() {
const [count, setCount] = React.useState(5);
const { intl } = useLanguage();
const router = useRouter();

React.useEffect(() => {
if (count === 0) {
router.push(LOGIN_URL);
} else {
const timer = setTimeout(() => setCount(count - 1), 1_000);

return () => clearTimeout(timer);
}
}, [count, router]);

return (
<span
dangerouslySetInnerHTML={{
__html: intl.redirection.counter.replace('{count}', String(count)),
}}
/>
);
}
4 changes: 4 additions & 0 deletions src/app/[lang]/redirection/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.center {
display: flex;
justify-content: center;
}
70 changes: 70 additions & 0 deletions src/app/[lang]/redirection/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Typography } from '@mui/material';
import { redirect } from 'next/navigation';
import Image from 'next/image';

import { GridContainer, GridItem } from '@/components/elements/grid';
import { TextBody } from '@/components/elements/typography';
import { getDictionary } from '@/dictionaries';
import { Locale } from '@/i18n-config';
import { Counter } from './counter';

import AccountCreated from '@public/assets/account-created.svg';
import styles from './page.module.css';

type Props = { searchParams: { cedula: string }; params: { lang: Locale } };

export default async function RedirectionPage({ searchParams, params }: Props) {
const intl = await getDictionary(params.lang);
const cedula = searchParams.cedula;

if (!cedula) redirect('identification');

return (
<GridContainer>
<GridItem md={12} lg={12}>
<div className={styles.center}>
<Image
src={AccountCreated?.src}
alt="imagen de cuenta creada"
width={259}
height={225}
/>
</div>
<br />
<Typography
color="primary"
sx={{
fontSize: '24px',
fontWeight: '700',
textAlign: 'center',
}}
gutterBottom
>
{intl.redirection.title}
</Typography>
<TextBody textCenter gutterBottom>
<span
dangerouslySetInnerHTML={{
__html: intl.redirection.body.replace('{id}', cedula),
}}
/>
</TextBody>
</GridItem>

<GridItem md={12} lg={12}>
<div className={styles.center}>
<Typography
color="primary"
fontWeight={500}
fontSize="medium"
bgcolor="#0091ff20"
sx={{ px: 2, py: 1 }}
borderRadius={2}
>
<Counter />
</Typography>
</div>
</GridItem>
</GridContainer>
);
}
5 changes: 5 additions & 0 deletions src/dictionaries/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"policy": "Privacy Policy",
"faq": "Frequently Asked Questions"
},
"redirection": {
"title": "You are already registered",
"body": "You can start logging in with your ID <b>{id}</b> in a few seconds.",
"counter": "Redirecting in <b>{count}</b> seconds..."
},
"confirmation": {
"title": "We have sent you an email",
"subtitle": "Check your email and click on the confirmation link or use the confirmation code.",
Expand Down
5 changes: 5 additions & 0 deletions src/dictionaries/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"policy": "Política de privacidad",
"faq": "Preguntas frecuentes"
},
"redirection": {
"title": "Ya estás registrado",
"body": "Podrás iniciar sesión enseguida con tu cédula <b>{id}</b>.",
"counter": "Redirigiendo en <b>{count}</b> segundos..."
},
"confirmation": {
"title": "Te hemos enviado un correo",
"subtitle": "Revisa tu correo electrónico y haz clic en el enlace de confirmación o utiliza el código de confirmación.",
Expand Down

0 comments on commit d10bec3

Please sign in to comment.