From 04ce0ce3bb3c775891c0609daa48b74b940599c8 Mon Sep 17 00:00:00 2001 From: Emanuel Almeida Date: Mon, 1 Jan 2001 00:00:00 +0000 Subject: [PATCH] feat: add AuthWrapper component with login UI --- src/auth/AuthWrapper.tsx | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/auth/AuthWrapper.tsx diff --git a/src/auth/AuthWrapper.tsx b/src/auth/AuthWrapper.tsx new file mode 100644 index 0000000..38be1cf --- /dev/null +++ b/src/auth/AuthWrapper.tsx @@ -0,0 +1,79 @@ +import { useAuth } from 'react-oidc-context'; +import { ReactNode } from 'react'; + +interface AuthWrapperProps { + children: ReactNode; +} + +export function AuthWrapper({ children }: AuthWrapperProps) { + const auth = useAuth(); + + if (auth.isLoading) { + return ( +
+
+
+

A carregar...

+
+
+ ); + } + + if (auth.error) { + return ( +
+
+
+

Erro de Autenticação

+

{auth.error.message}

+ +
+
+ ); + } + + if (!auth.isAuthenticated) { + return ( +
+
+
🔐
+

Dashboard EAL

+

Faça login para aceder ao dashboard

+ +
+
+ ); + } + + return <>{children}; +} + +export function UserInfo() { + const auth = useAuth(); + + if (!auth.isAuthenticated) return null; + + return ( +
+ + {auth.user?.profile?.name || auth.user?.profile?.email} + + +
+ ); +}