database wf 8

This commit is contained in:
alma 2025-04-17 13:16:16 +02:00
parent 75039435eb
commit 58f0b37476
3 changed files with 27 additions and 10 deletions

View File

@ -8,10 +8,16 @@ export const metadata: Metadata = {
title: "Enkun - Connexion",
};
export default async function SignIn() {
export default async function SignIn({
searchParams,
}: {
searchParams: { callbackUrl?: string };
}) {
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("/");
}
@ -25,7 +31,7 @@ export default async function SignIn() {
backgroundRepeat: 'no-repeat'
}}
>
<SignInForm />
<SignInForm callbackUrl={searchParams.callbackUrl} />
</div>
);
}

View File

@ -1,18 +1,18 @@
"use client";
import { signIn } from "next-auth/react";
import { useSearchParams } from "next/navigation";
export function SignInForm() {
const searchParams = useSearchParams();
const callbackUrl = searchParams.get("callbackUrl") || "/";
interface SignInFormProps {
callbackUrl?: string;
}
export function SignInForm({ callbackUrl }: SignInFormProps) {
return (
<div className="text-center">
<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>
<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"
>
Commit

View File

@ -3,12 +3,23 @@ import { NextResponse } from "next/server";
export default withAuth(
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();
},
{
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: {
signIn: "/signin",