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({
-
-
- - - - Forgot Email? - -
-
-
- {/* */} - {/* - Forgot Email? - */} -
- {/* */} -
- + + + } + error={errors.email} + /> + {/* + Forgot Email? + */} Sign In diff --git a/sigap-website/src/applications/entities/models/contact-us.model.ts b/sigap-website/src/applications/entities/models/contact-us.model.ts index 97b238b..30533ac 100644 --- a/sigap-website/src/applications/entities/models/contact-us.model.ts +++ b/sigap-website/src/applications/entities/models/contact-us.model.ts @@ -27,23 +27,23 @@ export const selectContactUsSchema = z.object({ name: z.string(), email: z.string(), phone: z.string(), - message_type: z.string(), + typeMessage: z.string(), message_type_label: z.string(), message: z.string(), status: z.nativeEnum(statusEnum), - created_at: z.string(), - updated_at: z.string(), + createdAt: z.string(), + updatedAt: z.string(), }); export type ContactUs = z.infer; // Schema for form input -export const insertContactUsSchema = z.object({ - name: z.string(), - email: z.string(), - phone: z.string(), - typeMessage: z.string(), - message: z.string(), +export const insertContactUsSchema = selectContactUsSchema.pick({ + name: true, + email: true, + phone: true, + typeMessage: true, + message: true, }); export type ContactUsInsert = z.infer; diff --git a/sigap-website/utils/supabase/middleware.ts b/sigap-website/utils/supabase/middleware.ts index 638d5db..f050f5f 100644 --- a/sigap-website/utils/supabase/middleware.ts +++ b/sigap-website/utils/supabase/middleware.ts @@ -41,7 +41,9 @@ export const updateSession = async (request: NextRequest) => { // protected routes if (request.nextUrl.pathname === "/" && !user.error) { - return NextResponse.redirect(new URL("/protected", request.url)); + return NextResponse.redirect( + new URL("/protected/dashboard", request.url) + ); } if (request.nextUrl.pathname.startsWith("/protected") && user.error) {