import "server-only"

import { cookies } from "next/headers"

import { auth } from "@/auth"

import { isValidSession } from "./session"

export async function isLoggedInUser(): Promise<boolean> {
  const session = await auth()
  const cookieStore = await cookies()
  const webviewTokenCookie = cookieStore.get("webviewToken")

  // We assume we have a valid session if we have a webviewTokenCookie.
  return isValidSession(session) || !!webviewTokenCookie?.value
}
