database wf 8
This commit is contained in:
parent
75039435eb
commit
58f0b37476
@ -8,10 +8,16 @@ export const metadata: Metadata = {
|
|||||||
title: "Enkun - Connexion",
|
title: "Enkun - Connexion",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function SignIn() {
|
export default async function SignIn({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: { callbackUrl?: string };
|
||||||
|
}) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (session) {
|
// If user is already authenticated and there's no specific callback URL,
|
||||||
|
// redirect to the home page
|
||||||
|
if (session && !searchParams.callbackUrl) {
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +31,7 @@ export default async function SignIn() {
|
|||||||
backgroundRepeat: 'no-repeat'
|
backgroundRepeat: 'no-repeat'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SignInForm />
|
<SignInForm callbackUrl={searchParams.callbackUrl} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { signIn } from "next-auth/react";
|
import { signIn } from "next-auth/react";
|
||||||
import { useSearchParams } from "next/navigation";
|
|
||||||
|
|
||||||
export function SignInForm() {
|
interface SignInFormProps {
|
||||||
const searchParams = useSearchParams();
|
callbackUrl?: string;
|
||||||
const callbackUrl = searchParams.get("callbackUrl") || "/";
|
}
|
||||||
|
|
||||||
|
export function SignInForm({ callbackUrl }: SignInFormProps) {
|
||||||
return (
|
return (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<h1 className="text-4xl font-bold text-white mb-4">Bienvenue sur Enkun</h1>
|
<h1 className="text-4xl font-bold text-white mb-4">Bienvenue sur Enkun</h1>
|
||||||
<p className="text-white/80 mb-8">Connectez-vous pour accéder à votre espace</p>
|
<p className="text-white/80 mb-8">Connectez-vous pour accéder à votre espace</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => signIn("keycloak", { callbackUrl })}
|
onClick={() => signIn("keycloak", { callbackUrl: callbackUrl || "/" })}
|
||||||
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
||||||
>
|
>
|
||||||
Commit
|
Commit
|
||||||
|
|||||||
@ -3,12 +3,23 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export default withAuth(
|
export default withAuth(
|
||||||
function middleware(req) {
|
function middleware(req) {
|
||||||
// Add custom middleware logic here if needed
|
// Allow access to the root path and signin page
|
||||||
|
if (req.nextUrl.pathname === "/" || req.nextUrl.pathname === "/signin") {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// For all other routes, check authentication
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
callbacks: {
|
callbacks: {
|
||||||
authorized: ({ token }) => !!token,
|
authorized: ({ token, req }) => {
|
||||||
|
// Allow access to the root path and signin page
|
||||||
|
if (req.nextUrl.pathname === "/" || req.nextUrl.pathname === "/signin") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !!token;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
signIn: "/signin",
|
signIn: "/signin",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user