Issues getting access token in stateless mode v1.4.0

I am trying to get the users access token on the server using the command below like it says in the docs, I am currently using stateless mode with a cognito social provider. I am using Next.js v15.5.6 and I have tried using both the bearer plugin and the nextCookies plugin.

My flow is
home page ->
authClient.signIn.social({ provider: "cognito" })
which redirects me to the home page -> then i go to my (authenticated) routes which has the get access token in the layout and i get an account not found error.

is this not possible in stateless mode. Thank you for any help

https://www.better-auth.com/docs/concepts/oauth#get-access-token
const session = await auth.api.getAccessToken({
    body: {
      providerId: "cognito",
    },
    headers: await headers(),
  });


import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";

export const auth = betterAuth({
  socialProviders: {
    cognito: {
      clientId: process.env.COGNITO_CLIENT_ID!,
      clientSecret: process.env.COGNITO_CLIENT_SECRET!,
      domain: process.env.COGNITO_DOMAIN!,
      region: process.env.COGNITO_REGION!,
      userPoolId: process.env.COGNITO_USERPOOL_ID!,
    },
  },
  plugins: [nextCookies()],
});

export type Session = typeof auth.$Infer.Session;
How Better Auth handles OAuth
Was this page helpful?