From 55900bb4605dc4b4e6c4fa2f5193e44633a728ab Mon Sep 17 00:00:00 2001 From: dotX12 Date: Sun, 26 Jan 2025 16:57:58 +0300 Subject: [PATCH] Update LoginPage to use Suspense for consistent error handling. Read: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout --- authentication/src/app/flow/login/page.tsx | 156 +++++++++++---------- 1 file changed, 80 insertions(+), 76 deletions(-) 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 ? ( - + {flow ? ( + ) : ( -
- { - flow ? - - : - - } - { - flow ? - - : - - } +
+
+ + +
+
+ + +
+
- ) - } + )} + + {flow?.requested_aal === 'aal2' || flow?.requested_aal === 'aal3' || flow?.refresh ? ( + + ) : ( +
+ {flow ? ( + + ) : ( + + )} + {flow ? ( + + ) : ( + + )} +
+ )} ); }