-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
93 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,19 @@ | ||
"use client"; | ||
import { signIn, useSession } from "next-auth/react"; | ||
import { login } from "@/services/auth"; | ||
import { useSession } from "next-auth/react"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect, useRef } from "react"; | ||
import { useEffect } from "react"; | ||
|
||
export default function SignIn() { | ||
const { data, status } = useSession(); | ||
const { status } = useSession(); | ||
const router = useRouter(); | ||
const signedIn = useRef(false); | ||
const signingIn = useRef(false); | ||
|
||
useEffect(() => { | ||
const login = async () => { | ||
switch (status) { | ||
case "unauthenticated": | ||
if (!signingIn.current) { | ||
console.debug("signing in, redirecting to IAM login service..."); | ||
await signIn("indigo-iam", { callbackUrl: "/" }); | ||
signingIn.current = true; | ||
} | ||
break; | ||
case "loading": | ||
break; | ||
case "authenticated": | ||
if (!signedIn.current) { | ||
signedIn.current = true; | ||
console.debug("authenticated, redirecting to home"); | ||
router.push("/"); | ||
} | ||
break; | ||
} | ||
}; | ||
login(); | ||
}, [router, status, data]); | ||
if (status === "unauthenticated") { | ||
login(); | ||
} else if (status === "authenticated") { | ||
router.push("/"); | ||
} | ||
console.log(status); | ||
}, [status]); | ||
return <div>Redirecting to login page...</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ArrowRightEndOnRectangleIcon } from "@heroicons/react/24/solid"; | ||
import { logout } from "@/services/auth"; | ||
|
||
export const Logout = async () => { | ||
return ( | ||
<form | ||
action={logout} | ||
className="m-auto flex rounded-full p-2 hover:bg-primary-hover" | ||
> | ||
<button type="submit" className="size-6 text-secondary"> | ||
<ArrowRightEndOnRectangleIcon /> | ||
</button> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as Button } from "./Button"; | ||
export { Logout } from "./Logout"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use server"; | ||
import { signIn, signOut } from "@/auth"; | ||
import getConfig from "@/utils/config"; | ||
import { redirect } from "next/navigation"; | ||
const { BASE_URL } = getConfig(); | ||
|
||
export async function login() { | ||
await signIn("indigo-iam", { redirectTo: "/" }); | ||
} | ||
|
||
export async function logout() { | ||
await signOut({ redirect: false }); | ||
redirect(`${BASE_URL}/logout`); | ||
} |