diff --git a/.env b/.env index dc3a6d0b..5a31bc17 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -BASE_ROUTE = 'Base route' \ No newline at end of file +NEXT_PUBLIC_URL_SPID_LOGIN=http://localhost:9090/login \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 00000000..dbb6e8e5 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +NEXT_PUBLIC_URL_SPID_LOGIN=http://localhost:9090/login diff --git a/.env.local b/.env.local new file mode 100644 index 00000000..dbb6e8e5 --- /dev/null +++ b/.env.local @@ -0,0 +1 @@ +NEXT_PUBLIC_URL_SPID_LOGIN=http://localhost:9090/login diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..dbb6e8e5 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +NEXT_PUBLIC_URL_SPID_LOGIN=http://localhost:9090/login diff --git a/src/app/[locale]/(pages)/access/page.tsx b/src/app/[locale]/(pages)/access/page.tsx index 64c58948..9e2ba611 100644 --- a/src/app/[locale]/(pages)/access/page.tsx +++ b/src/app/[locale]/(pages)/access/page.tsx @@ -4,10 +4,17 @@ import { CieIcon } from '@pagopa/mui-italia/dist/icons/CieIcon'; import { SpidIcon } from '@pagopa/mui-italia/dist/icons/SpidIcon'; import { useTranslations } from 'next-intl'; import Link from 'next/link'; +import { useState } from 'react'; import { ROUTES } from '../../_utils/routes'; +import { SelectIdp } from '../../_component/selectIdp/selectIdp'; +import { SpidLevels } from '../../_component/selectIdp/idpList'; const Access = (): React.ReactElement => { + const [openDialog, setOpenDialog] = useState(false); const t = useTranslations('access'); + const spidLevel: SpidLevels = { + type: 'L2', + }; return ( @@ -68,7 +75,7 @@ const Access = (): React.ReactElement => { width: '100%', height: '50px', }} - // onClick={() => setShowIDPS(true)} + onClick={() => setOpenDialog(true)} variant="contained" startIcon={} > @@ -154,6 +161,13 @@ const Access = (): React.ReactElement => { + { + setOpenDialog(opn); + }} + /> ); }; diff --git a/src/app/[locale]/(pages)/logoutInit/page.tsx b/src/app/[locale]/(pages)/logoutInit/page.tsx index 90fd17c0..69f82e51 100644 --- a/src/app/[locale]/(pages)/logoutInit/page.tsx +++ b/src/app/[locale]/(pages)/logoutInit/page.tsx @@ -9,10 +9,16 @@ import { Introduction } from '../../_component/introduction/introduction'; import { commonBackgroundDark } from '../../_utils/styles'; import { FAQ } from '../../_component/accordion/faqDefault'; import { SelectIdp } from '../../_component/selectIdp/selectIdp'; +import { SpidLevels } from '../../_component/selectIdp/idpList'; const Init = (): React.ReactElement => { const t = useTranslations('logout'); const [openDialog, setOpenDialog] = useState(false); + + const spidLevel: SpidLevels = { + type: 'L1', + }; + return ( <> @@ -64,12 +70,7 @@ const Init = (): React.ReactElement => { - { - setOpenDialog(opn); - }} - /> + ); }; diff --git a/src/app/[locale]/(pages)/validateSession/page.tsx b/src/app/[locale]/(pages)/validateSession/page.tsx index dbac57c0..d29d5e23 100644 --- a/src/app/[locale]/(pages)/validateSession/page.tsx +++ b/src/app/[locale]/(pages)/validateSession/page.tsx @@ -1,21 +1,20 @@ 'use client'; -import { redirect } from 'next/navigation'; import { useEffect } from 'react'; -import { ROUTES } from '../../_utils/routes'; -import useToken from '../../_hooks/useToken'; +import { redirect } from 'next/navigation'; import Loader from '../../_component/loader/loader'; +import { extractToken, parseJwt, userFromJwtToken } from '../../_utils/jwt'; +import { storageTokenOps, storageUserOps } from '../../_utils/storage'; +import { ROUTES } from '../../_utils/routes'; const Check = (): React.ReactElement => { - const { tokenError } = useToken(); - useEffect(() => { - if (tokenError === 'ERROR') { - redirect(ROUTES.LOGOUT_AUTH_KO); - } - if (tokenError === 'OK') { + if (parseJwt(extractToken())) { + // FIXME: Jira ticket number 521 + storageTokenOps.write(extractToken()); + storageUserOps.write(userFromJwtToken(extractToken())); redirect(ROUTES.SESSION); } - }, [tokenError]); + }, []); return ( <> diff --git a/src/app/[locale]/_component/header/header.tsx b/src/app/[locale]/_component/header/header.tsx index 9d56b53e..ffdf4cd8 100644 --- a/src/app/[locale]/_component/header/header.tsx +++ b/src/app/[locale]/_component/header/header.tsx @@ -1,7 +1,6 @@ 'use client'; import { HeaderAccount, HeaderProduct, LogoIOApp } from '@pagopa/mui-italia'; import React from 'react'; -import { IconButton } from '@mui/material'; import useLogin from '../../_hooks/useLogin'; const Header = (): React.ReactElement => { @@ -37,17 +36,6 @@ const Header = (): React.ReactElement => { }} enableLogin={isLoggedIn} enableAssistanceButton={true} - userActions={[ - { - id: 'logout', - label: 'Esci', - onClick: () => { - // eslint-disable-next-line no-console - console.log('User logged out'); - }, - icon: , - }, - ]} /> { - window.location.assign(`http://localhost:9090/login?entityID=${IDP.entityId}&authLevel=SpidL1`); + window.location.assign( + `${process.env.NEXT_PUBLIC_URL_SPID_LOGIN}?entityID=${IDP.entityId}&authLevel=Spid${spidLevel.type}` + ); }; return ( diff --git a/src/app/[locale]/_component/selectIdp/selectIdp.tsx b/src/app/[locale]/_component/selectIdp/selectIdp.tsx index 6efe2074..0afe5058 100644 --- a/src/app/[locale]/_component/selectIdp/selectIdp.tsx +++ b/src/app/[locale]/_component/selectIdp/selectIdp.tsx @@ -1,18 +1,23 @@ import { Box, Button, Dialog, Typography } from '@mui/material'; import React, { useEffect, useState } from 'react'; -import { IdpList } from './idpList'; +import { IdpList, SpidLevels } from './idpList'; interface IDialog { - open: boolean; + isOpen: boolean; + spidLevel: SpidLevels; onClose: (open: boolean, event: React.MouseEvent) => void; } -export function SelectIdp({ open, onClose }: IDialog) { +export function SelectIdp({ isOpen, spidLevel, onClose }: IDialog) { const [openDialog, setOpenDialog] = useState(false); useEffect(() => { - setOpenDialog(open); - }, [open]); + setOpenDialog(isOpen); + }, [isOpen]); + + const level: SpidLevels = { + type: spidLevel.type, + }; return ( <> @@ -29,7 +34,7 @@ export function SelectIdp({ open, onClose }: IDialog) { > {'Scegli il tuo Identity Provider'} - +