"use client"
import { redirect } from "next/navigation"
import { useEffect } from "react"
import { usePostHog } from "posthog-js/react"
import { useUser } from "@auth0/nextjs-auth0/client"

export default function AppHomePage(): void {
  const posthog = usePostHog()
  const session = useUser()


  useEffect(() => {
      if (session?.user?.sub) {
        posthog?.identify(session.user.sub, {
          username: session.user.nickname,
          name: session.user.name,
          email: session.user.email,
        })
        // posthog?.group("company", user.company_id)
        redirect("/app/apikeys")
      } else {
        redirect("/login")
      }
    },
    [posthog, session?.user?.email, session?.user?.name, session?.user?.nickname, session?.user?.sub],
  )
}
