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",
    };
  }
};
