diff --git a/sigap-website/actions/auth/session.ts b/sigap-website/actions/auth/session.ts
new file mode 100644
index 0000000..15e1f75
--- /dev/null
+++ b/sigap-website/actions/auth/session.ts
@@ -0,0 +1,39 @@
+"use server";
+
+import { createClient } from "@/utils/supabase/server";
+
+export const checkSession = async () => {
+ const supabase = await createClient();
+
+ try {
+ const {
+ data: { session },
+ error,
+ } = await supabase.auth.getSession();
+
+ if (error) {
+ return {
+ success: false,
+ error: error.message,
+ };
+ }
+
+ if (session) {
+ return {
+ success: true,
+ session,
+ redirectTo: "/protected/dashboard", // or your preferred authenticated route
+ };
+ }
+
+ return {
+ success: false,
+ message: "No active session",
+ };
+ } catch (error) {
+ return {
+ success: false,
+ error: "An unexpected error occurred",
+ };
+ }
+};
diff --git a/sigap-website/app/(auth-pages)/layout.tsx b/sigap-website/app/(auth-pages)/layout.tsx
index e3980ef..ccb5d43 100644
--- a/sigap-website/app/(auth-pages)/layout.tsx
+++ b/sigap-website/app/(auth-pages)/layout.tsx
@@ -1,9 +1,17 @@
+import { checkSession } from "@/actions/auth/session";
+import { redirect } from "next/navigation";
+
export default async function Layout({
children,
}: {
children: React.ReactNode;
}) {
- return (
-
{children}
- );
+ const sessionResult = await checkSession();
+
+ // If there's an active session, redirect to dashboard
+ if (sessionResult.success && sessionResult.redirectTo) {
+ redirect(sessionResult.redirectTo);
+ }
+
+ return {children}
;
}
diff --git a/sigap-website/app/(auth-pages)/sign-in/page.tsx b/sigap-website/app/(auth-pages)/sign-in/page.tsx
index 68dfd0e..e1a84c6 100644
--- a/sigap-website/app/(auth-pages)/sign-in/page.tsx
+++ b/sigap-website/app/(auth-pages)/sign-in/page.tsx
@@ -1,5 +1,4 @@
import { FormMessage, Message } from "@/components/form-message";
-import { LoginForm } from "@/components/auth/login-form";
import { SubmitButton } from "@/components/submit-button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
diff --git a/sigap-website/app/layout.tsx b/sigap-website/app/layout.tsx
index 172c969..b47a6a6 100644
--- a/sigap-website/app/layout.tsx
+++ b/sigap-website/app/layout.tsx
@@ -31,6 +31,7 @@ export default function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
+
return (
diff --git a/sigap-website/components/auth/login-form-2.tsx b/sigap-website/components/auth/login-form-2.tsx
index 1a87fd0..226e8bc 100644
--- a/sigap-website/components/auth/login-form-2.tsx
+++ b/sigap-website/components/auth/login-form-2.tsx
@@ -1,16 +1,29 @@
-import { cn } from "@/lib/utils";
+"use client";
+
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
+
import { Github, Lock } from "lucide-react";
import Link from "next/link";
import { SubmitButton } from "../submit-button";
-import { signInAction } from "@/actions/auth/sign-in";
+
+import { FormField } from "../form-field";
+import { useSignInForm } from "@/src/infrastructure/hooks/use-signin";
export function LoginForm2({
className,
...props
}: React.ComponentPropsWithoutRef<"form">) {
+ const {
+ formData,
+ errors,
+ isSubmitting,
+ setFormData,
+ handleChange,
+ handleSelectChange,
+ handleSubmit,
+ } = useSignInForm();
+
return (
@@ -35,6 +48,7 @@ export function LoginForm2({
variant="outline"
className="w-full bg-[#1C1C1C] text-white border-gray-800 hover:bg-[#2C2C2C] hover:border-gray-700"
size="lg"
+ disabled={isSubmitting}
>
Continue with SSO
@@ -50,51 +64,35 @@ export function LoginForm2({
-