Have anyone manage to get OIDC working with genericOauth
i keep getting this error 
This is my current config im trying to get my cusotm OIDC working having hard time what im ia doing in correct also note this token i checked database it exits and try it also with Postgress same issue so adapater isnt the issue
2025-08-28T15:24:05.992Z ERROR [Better Auth]: State Mismatch. Verification not found {
  state: "SAWTsHvhONj2IiZKdnrNB98AXUhs1X3L",
}
2025-08-28T15:24:05.992Z ERROR [Better Auth]: State Mismatch. Verification not found {
  state: "SAWTsHvhONj2IiZKdnrNB98AXUhs1X3L",
}
export const auth: any = betterAuth({
  database: surrealAdapter({
    endpoint: env.SURREALDB_ENDPOINT,
    database: env.SURREALDB_DATABASE,
    namespace: env.SURREALDB_NAMESPACE,
    auth: {
      password: env.SURREALDB_PASSWORD,
      username: env.SURREALDB_USERNAME,
    },
  }),
  account: {
    accountLinking: {
      enabled: true,
      trustedProviders: ["email-password", "discord", "unified"],
      allowDifferentEmails: true,
    },
  },
  emailAndPassword: {
    enabled: true,
  },
  trustedOrigins: env.ALLOWED_ORIGINS.split(","),
  plugins: [
    admin(),
    openAPI(),
    jwt(),
    genericOAuth({
      config: [
        {
          providerId: "unified",
          clientId: env.OAUTH_CLIENT_ID,
          clientSecret: env.OAUTH_CLIENT_SECRET,
          discoveryUrl: `${env.BETTER_AUTH_URL}/api/auth/.well-known/openid-configuration`,
          scopes: ["openid", "email", "profile"],
        },
      ],
    }),
    oidcProvider({
      loginPage: env.OIDC_LOGIN_PAGE_URL,
      trustedClients: [
        {
          clientId: env.OAUTH_CLIENT_ID,
          clientSecret: env.OAUTH_CLIENT_SECRET,
          disabled: false,
          metadata: {},
          name: "unified",
          type: "web",
          skipConsent: true,
          redirectURLs: [
            `${env.BETTER_AUTH_URL}/api/auth/oauth2/callback/unified`,
          ],
        },
      ],
    }),
  ],
});
export const auth: any = betterAuth({
  database: surrealAdapter({
    endpoint: env.SURREALDB_ENDPOINT,
    database: env.SURREALDB_DATABASE,
    namespace: env.SURREALDB_NAMESPACE,
    auth: {
      password: env.SURREALDB_PASSWORD,
      username: env.SURREALDB_USERNAME,
    },
  }),
  account: {
    accountLinking: {
      enabled: true,
      trustedProviders: ["email-password", "discord", "unified"],
      allowDifferentEmails: true,
    },
  },
  emailAndPassword: {
    enabled: true,
  },
  trustedOrigins: env.ALLOWED_ORIGINS.split(","),
  plugins: [
    admin(),
    openAPI(),
    jwt(),
    genericOAuth({
      config: [
        {
          providerId: "unified",
          clientId: env.OAUTH_CLIENT_ID,
          clientSecret: env.OAUTH_CLIENT_SECRET,
          discoveryUrl: `${env.BETTER_AUTH_URL}/api/auth/.well-known/openid-configuration`,
          scopes: ["openid", "email", "profile"],
        },
      ],
    }),
    oidcProvider({
      loginPage: env.OIDC_LOGIN_PAGE_URL,
      trustedClients: [
        {
          clientId: env.OAUTH_CLIENT_ID,
          clientSecret: env.OAUTH_CLIENT_SECRET,
          disabled: false,
          metadata: {},
          name: "unified",
          type: "web",
          skipConsent: true,
          redirectURLs: [
            `${env.BETTER_AUTH_URL}/api/auth/oauth2/callback/unified`,
          ],
        },
      ],
    }),
  ],
});
0 Replies