Budibase/budibase · error

Unable to retrieve datasource authentication cookie

Error message

Unable to retrieve datasource authentication cookie

What it means

datasourceAuth middleware handles the OAuth callback for datasource logins. It reads a DatasourceAuth cookie that was set when the flow started; if the cookie is absent the middleware cannot determine which provider handler to invoke and throws immediately.

Source

Thrown at packages/worker/src/api/controllers/global/auth.ts:310

    ctx,
    {
      provider,
      appId: ctx.query.appId,
      returnPath,
    },
    Cookie.DatasourceAuth
  )

  return handler.preAuth(passport, ctx, next)
}

export const datasourceAuth = async (ctx: UserCtx<void, void>, next: Next) => {
  const authStateCookie = getCookie<DatasourceAuthCookie>(
    ctx,
    Cookie.DatasourceAuth
  )
  if (!authStateCookie) {
    throw new Error("Unable to retrieve datasource authentication cookie")
  }
  const provider = authStateCookie.provider
  const { middleware } = require(`@budibase/backend-core`)
  const handler = middleware.datasource[provider]
  if (!handler) {
    ctx.throw(400, "Unsupported datasource provider")
  }
  return handler.postAuth(passport, ctx, next)
}

// GOOGLE SSO

export async function googleCallbackUrl(config?: GoogleInnerConfig) {
  return ssoCallbackUrl(ConfigType.GOOGLE, config)
}

/**
 * The initial call that google authentication makes to take you to the google login screen.

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Restart the datasource OAuth flow from the beginning so a fresh DatasourceAuth cookie is set
  2. Check browser cookie settings / disable third-party cookie blocking for the Budibase domain
  3. Ensure the OAuth provider redirect stays on the same domain so the cookie is transmitted
  4. Confirm the time between initiating auth and callback is shorter than the cookie expiry
Defensive patterns

Strategy: validation

Validate before calling

const cookie = ctx.cookies.get(Cookie.DatasourceAuth)
if (!cookie) {
  // redirect to re-initiate the datasource OAuth flow instead of proceeding
  return ctx.redirect("/api/datasources/auth/init")
}

Type guard

function hasDatasourceAuthCookie(c: unknown): c is DatasourceAuthCookie {
  return c != null && typeof c === "object" && "provider" in c
}

Prevention

When it happens

Trigger: Hitting the datasource auth callback endpoint without a DatasourceAuth cookie: the cookie expired, was blocked/cleared by the browser, was stripped by cross-site cookie policies, or the endpoint was opened directly instead of through the OAuth flow.

Common situations: Third-party cookie blocking in Safari/incognito, redirect flows crossing different domains so the cookie is not sent, long-running OAuth flows outlasting cookie expiry, users bookmarking or sharing the callback URL.

Understand the failure class

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/b27e6ce19864b767. Report an issue: GitHub.