import type { Session } from "next-auth"

export function isValidClientSession(session: Session | null) {
  if (!session) {
    return false
  }
  if (session.error) {
    console.log(`Session error: ${session.error}`)
    return false
  }

  if (session.token.error) {
    console.log(`Session token error: ${session.token.error}`)
    return false
  }
  if (session.token.expires_at && session.token.expires_at < Date.now()) {
    console.log(`Session expired: ${session.token.expires_at}`)
    return false
  }

  return true
}
