force sign on via keycloak if not authenticated
Change-Id: I3b3512359cb26435013ab308f418ff42297e5d4b
Reviewed-on: https://git.clicks.codes/c/Clicks/Dashboard/+/27
Tested-by: Samuel Shuert <coded@clicks.codes>
Reviewed-by: Skyler Grey <minion@clicks.codes>
diff --git a/components/login-btn.tsx b/components/login-btn.tsx
deleted file mode 100644
index 6b9af8f..0000000
--- a/components/login-btn.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { useSession, signIn, signOut } from "next-auth/react"
-export default function Component() {
- const { data: session } = useSession()
- if (session) {
- return (
- <>
- Signed in as {session.user!.email} <br />
- <button onClick={() => signOut()}>Sign out</button>
- </>
- )
- }
- return (
- <>
- Not signed in <br />
- <button onClick={() => signIn()}>Sign in</button>
- </>
- )
-}
-
diff --git a/pages/_app.tsx b/pages/_app.tsx
index fab598b..0cf3611 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -1,4 +1,5 @@
import { SessionProvider } from "next-auth/react"
+import "../app/globals.css";
export default function App({
//@ts-expect-error
diff --git a/pages/index.tsx b/pages/index.tsx
index 78e3e9e..861890a 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,7 +1,18 @@
-import Loginbtn from '../components/login-btn.tsx'
+import { useSession, signIn, signOut } from 'next-auth/react'
+import { useEffect } from 'react';
export default function Home() {
+ const { data: session, status } = useSession();
+
+ useEffect(() => {
+ if (status === 'unauthenticated') {
+ void signIn('keycloak');
+ }
+ }, [status]);
return (
- <Loginbtn />
+ <div>
+ Signed in as {session?.user?.name}
+ <button onClick={() => signOut()}>Sign Out</button>
+ </div>
)
}
\ No newline at end of file