unionlabs/union · error · Error

User ID is required

Error message

User ID is required

What it means

Companion guard to the session check in getContributionState: a session exists but session.user.id is falsy, so there is no userId to pass to queryContributor/querySubmittedContribution/etc. It indicates a degenerate session object rather than a logged-out user.

Source

Thrown at ceremony/src/lib/supabase/index.ts:92

      inQueue: false,
      message: "User not found in the queue",
    }
  }

  return {
    inQueue: true,
    count: count,
    ...data,
  }
}

export const getContributionState = async (): Promise<ContributionState> => {
  if (!user.session) {
    throw new Error("User is not logged in")
  }
  const userId = user.session.user.id
  if (!userId) {
    throw new Error("User ID is required")
  }

  try {
    const [contributor, submittedContribution, verifiedContribution, contributionWindow] =
      await Promise.all([
        queryContributor(userId),
        querySubmittedContribution(userId),
        queryContribution(userId),
        queryContributionWindow(userId),
      ])

    const isContributor = !!contributor?.data
    const hasSubmitted = !!submittedContribution?.data
    const hasVerified = !!verifiedContribution?.data
    const isExpired = contributionWindow?.data?.expire
      ? Date.now() > new Date(contributionWindow.data.expire).getTime()
      : false

View on GitHub (pinned to 031785bb6d)

Solutions

  1. Sign out and sign in again to rebuild a well-formed session
  2. Validate session.user.id (not just session) before calling getContributionState
  3. Clear stale Supabase auth keys from localStorage if the problem persists

Example fix

// before
if (!user.session) throw new Error("User is not logged in")
const userId = user.session.user.id

// after
const userId = user.session?.user?.id
if (!userId) {
  await supabase.auth.signOut()
  throw new Error("User is not logged in")
}
Defensive patterns

Strategy: validation

Validate before calling

const userId = user.session?.user?.id
if (!userId) {
  await supabase.auth.signOut()
  await goto("/login")
  return
}
await getContributionState()

Type guard

const hasUserId = (s: Session | null): s is Session & { user: { id: string } } =>
  typeof s?.user?.id === "string" && s.user.id.length > 0

Try / catch

try {
  await getContributionState()
} catch (e) {
  if (e instanceof Error && e.message === "User ID is required") {
    await supabase.auth.signOut()
    await goto("/login")
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Partially restored or malformed session (token without user payload); session persisted by an older Supabase client version after a project update.

Common situations: Post-migration stale auth state in localStorage; interrupted sign-in callbacks.

Related errors


AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16). Data as JSON: /api/errors/c99db2c6ebe38809. Report an issue: GitHub.