diff --git a/authentication/src/app/flow/login/page.tsx b/authentication/src/app/flow/login/page.tsx index 8a689d0..304b522 100644 --- a/authentication/src/app/flow/login/page.tsx +++ b/authentication/src/app/flow/login/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useCallback, useEffect, useState } from 'react'; +import React, {Suspense, useCallback, useEffect, useState} from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Flow, HandleError, kratos, LogoutLink } from '@/ory'; import Link from 'next/link'; @@ -11,8 +11,15 @@ import Image from 'next/image'; import { Skeleton } from '@/components/ui/skeleton'; import { AxiosError } from 'axios'; -export default function Login() { +export default function LoginPage() { + return ( + + + + ) +} +function Login() { const [flow, setFlow] = useState(); const router = useRouter(); @@ -65,19 +72,27 @@ export default function Login() { }; useEffect(() => { + const fetchFlow = async () => { + if (flow) { + return; + } - if (flow) { - return; - } + try { + if (flowId) { + await getFlow(flowId); + return; + } - if (flowId) { - getFlow(flowId).then(); - return; - } + createFlow(aal, refresh, returnTo, loginChallenge); + } catch (err) { + console.error("Error in registration flow:", err); + } + }; - createFlow(aal, refresh, returnTo, loginChallenge); - - }, [flowId, router, aal, refresh, returnTo, createFlow, loginChallenge, getFlow]); + fetchFlow().catch((err) => + console.error("Unhandled error in fetchFlow:", err) + ); + }, [flowId, router, aal, refresh, returnTo, createFlow, loginChallenge, getFlow, flow]); return ( @@ -88,23 +103,20 @@ export default function Login() { alt="Markus Thielker Intranet"/> { - flow ? + flow ? ( - { - (() => { - if (flow?.refresh) { - return 'Confirm Action'; - } else if (flow?.requested_aal === 'aal2') { - return 'Two-Factor Authentication'; - } - return 'Welcome'; - })()} + + {flow.refresh + ? 'Confirm Action' + : flow.requested_aal === 'aal2' + ? 'Two-Factor Authentication' + : 'Welcome'} Log in to the Intranet to access all locally hosted applications. - : + ) : ( @@ -112,64 +124,56 @@ export default function Login() { + ) } - { - flow - ? - : ( - - - - - - - - - - - - - - ) - } - - { - flow?.requested_aal === 'aal2' || flow?.requested_aal === 'aal3' || flow?.refresh ? ( - - Log out - + {flow ? ( + ) : ( - - { - flow ? - - Forgot your password? - - - : - - } - { - flow ? - - - Create an account - - - : - - } + + + + + + + + + + + + - ) - } + )} + + {flow?.requested_aal === 'aal2' || flow?.requested_aal === 'aal3' || flow?.refresh ? ( + + Log out + + ) : ( + + {flow ? ( + + + Forgot your password? + + + ) : ( + + )} + {flow ? ( + + + Create an account + + + ) : ( + + )} + + )} ); }