import supa from '@/components/supadb/aksupainstance.uts'

export function getUserIdOrNull(): string | null {
  try {
    const sessionInfo = supa.getSession()
    if (sessionInfo == null || sessionInfo.user == null) return null
    const userObj = sessionInfo.user as any
    if (userObj.getString != null) {
      return (userObj.getString('id') as string | null)
    }
    if (userObj.id != null) {
      return String(userObj.id)
    }
    if (typeof userObj === 'object' && 'id' in userObj) {
      return String((userObj as any).id)
    }
    return null
  } catch (e) {
    return null
  }
}
