Google social provider crashes with socialProviders[key] is not a function in next.js 16 & pnpm #2577

Closed
opened 2026-03-13 10:04:25 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @anselumjuju on GitHub (Dec 19, 2025).

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • Create a Next.js App Router project using pnpm
  • Configure Better Auth with Prisma adapter
  • Add Google social provider
  • Create auth route:
    app/api/auth/[...better-auth]/route.ts
  • Call:
    await signIn.social({ provider: "google" });

Current vs. Expected behavior

Server crashes with:

TypeError: socialProviders[key] is not a function
at createAuthContext
at init

What version of Better Auth are you using?

1.4.7

System info

$ npx @better-auth/cli info --json
{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home Single Language",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600H with Radeon Graphics         ",
    "totalMemory": "7.36 GB",
    "freeMemory": "0.97 GB"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.3"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.10"
    },
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "@prisma/client",
      "version": "^7.2.0"
    }
  ],
  "betterAuth": {
    "version": "^1.4.7",
    "config": {
      "emailAndPassword": {
        "enabled": true
      },
      "socialProviders": {
        "google": {
          "clientId": "",
          "clientSecret": "[REDACTED]"
        },
        "user": {
          "additionalFields": {
            "role": {
              "type": "string",
              "input": false,
              "defaultValue": "user"
            }
          }
        }
      }
    }
  }
}
file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:75
                const provider = socialProviders[key](config);
                                                     ^

TypeError: socialProviders[key] is not a function
    at file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:75:40
    at Array.map (<anonymous>)
    at createAuthContext (file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:71:66)
    at init (file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/init.mjs:11:20)

Node.js v24.11.1

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import {betterAuth} from 'better-auth';
import {prismaAdapter} from 'better-auth/adapters/prisma';
import prisma from '@/lib/prisma';

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  emailAndPassword: {
    enabled: true,
  },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    },
    user: {
      additionalFields: {
        role: {
          type: 'string',
          input: false,
          defaultValue: 'user',
        },
      },
    },
  },
});

Additional context

The error Log

POST /api/auth/sign-in/social 500 in 3.1s (compile: 2.8s, render: 297ms)
D:\Projects\project1.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1..js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: Error: sourceMapURL could not be parsed
Unhandled Rejection: TypeError: TURBOPACK__imported__module$5b$project$5d2f$node_modules$2f2e$pnpm$2f40$better$2d$auth$2b$core$40$1$2e$4$2e$7
$40$be_fb3fbdea1da4faecf62794f0118afd45$2f$node_modules$2f40$better$2d$auth$2f$core$2f$dist$2f$social$2d$providers$2f$index$2e$mjs__$5b$app$2d$route$5d$$28$ecmascript$29$.socialProviders[key] is not a function
at (D:\Projects\project1.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1..js:8366:338)
at Array.map ()
at createAuthContext (D:\Projects\project1.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1.
.js:8362:69)
at init (D:\Projects\project1.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1._.js:8495:326)

Originally created by @anselumjuju on GitHub (Dec 19, 2025). Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - Create a Next.js App Router project using pnpm - Configure Better Auth with Prisma adapter - Add Google social provider - Create auth route: app/api/auth/[...better-auth]/route.ts - Call: await signIn.social({ provider: "google" }); ### Current vs. Expected behavior Server crashes with: TypeError: socialProviders[key] is not a function at createAuthContext at init ### What version of Better Auth are you using? 1.4.7 ### System info ```bash $ npx @better-auth/cli info --json { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home Single Language", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600H with Radeon Graphics ", "totalMemory": "7.36 GB", "freeMemory": "0.97 GB" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.3" }, "frameworks": [ { "name": "next", "version": "16.0.10" }, { "name": "react", "version": "19.2.3" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "@prisma/client", "version": "^7.2.0" } ], "betterAuth": { "version": "^1.4.7", "config": { "emailAndPassword": { "enabled": true }, "socialProviders": { "google": { "clientId": "", "clientSecret": "[REDACTED]" }, "user": { "additionalFields": { "role": { "type": "string", "input": false, "defaultValue": "user" } } } } } } } file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:75 const provider = socialProviders[key](config); ^ TypeError: socialProviders[key] is not a function at file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:75:40 at Array.map (<anonymous>) at createAuthContext (file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/create-context.mjs:71:66) at init (file:///D:/Projects/veona/node_modules/.pnpm/better-auth@1.4.7_@prisma+c_dab71ba55678d881a31405d93a58d8b1/node_modules/better-auth/dist/context/init.mjs:11:20) Node.js v24.11.1 ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import {betterAuth} from 'better-auth'; import {prismaAdapter} from 'better-auth/adapters/prisma'; import prisma from '@/lib/prisma'; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), emailAndPassword: { enabled: true, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, user: { additionalFields: { role: { type: 'string', input: false, defaultValue: 'user', }, }, }, }, }); ``` ### Additional context The error Log POST /api/auth/sign-in/social 500 in 3.1s (compile: 2.8s, render: 297ms) D:\Projects\project1\.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1._.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: Error: sourceMapURL could not be parsed Unhandled Rejection: TypeError: __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f40$better$2d$auth$2b$core$40$1$2e$4$2e$7_$40$be_fb3fbdea1da4faecf62794f0118afd45$2f$node_modules$2f40$better$2d$auth$2f$core$2f$dist$2f$social$2d$providers$2f$index$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__.socialProviders[key] is not a function at <unknown> (D:\Projects\project1\.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1._.js:8366:338) at Array.map (<anonymous>) at createAuthContext (D:\Projects\project1\.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1._.js:8362:69) at init (D:\Projects\project1\.next\dev\server\chunks\59fa6_better-auth_dist_c09640b1._.js:8495:326)
GiteaMirror added the social-providernextjs labels 2026-03-13 10:04:25 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 19, 2025):

It seems you are encountering a TypeError: socialProviders[key] is not a function when trying to use the Google social provider with Better Auth in your Next.js application. This issue typically arises when the social provider is not properly registered or configured in your setup.

Here are some steps to troubleshoot this issue:

  1. Config Double-Check: Make sure your Google social provider is correctly set up in your Better Auth configuration. Check that the clientId and clientSecret are being set correctly, and that they match what is provided in your Google Developer Console.

  2. Version Compatibility: Ensure you are using compatible versions of better-auth, next.js, and any adapters. Since you are using version 1.4.7 of Better Auth, cross-check the release notes for that version for breaking changes or required configuration updates.

  3. Review Function Calls: Carefully inspect the code where you call await signIn.social({ provider: "google" }); and ensure that all related code leading to this call is properly structured as per the documentation of Better Auth.

  4. Check for Existing Issues: There are past discussions regarding the integration of Google as a social provider, indicating similar issues. You might find relevant solutions or workarounds in the GitHub issues for Better Auth related to social login [1][2].

If these steps do not resolve your issue, please tag Beka or Max (@bekacru or @ping__) in your next message to get further assistance directly from the team.

Would you like to provide any additional details about your setup that might help identify the problem?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 19, 2025): It seems you are encountering a `TypeError: socialProviders[key] is not a function` when trying to use the Google social provider with Better Auth in your Next.js application. This issue typically arises when the social provider is not properly registered or configured in your setup. Here are some steps to troubleshoot this issue: 1. **Config Double-Check**: Make sure your Google social provider is correctly set up in your Better Auth configuration. Check that the `clientId` and `clientSecret` are being set correctly, and that they match what is provided in your Google Developer Console. 2. **Version Compatibility**: Ensure you are using compatible versions of `better-auth`, `next.js`, and any adapters. Since you are using version 1.4.7 of Better Auth, cross-check the release notes for that version for breaking changes or required configuration updates. 3. **Review Function Calls**: Carefully inspect the code where you call `await signIn.social({ provider: "google" });` and ensure that all related code leading to this call is properly structured as per the documentation of Better Auth. 4. **Check for Existing Issues**: There are past discussions regarding the integration of Google as a social provider, indicating similar issues. You might find relevant solutions or workarounds in the GitHub issues for Better Auth related to social login [[1]](https://github.com/better-auth/better-auth/issues/5428)[[2]](https://github.com/better-auth/better-auth/issues/3401). If these steps do not resolve your issue, please tag Beka or Max (`@bekacru` or `@ping__`) in your next message to get further assistance directly from the team. Would you like to provide any additional details about your setup that might help identify the problem? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 19, 2025):

Hi @anselumjuju! I'm Dosu and I’m helping the better-auth team.

The crash happens because your config includes a non-provider key (user) inside socialProviders. Better Auth expects only supported provider keys (like google, github, etc.) in socialProviders, each mapping to a config object with clientId and clientSecret. When it encounters a key that isn't a known provider, it tries to call it as a function and throws the error you see example.

To fix this, remove the user key from socialProviders. If you want to add custom user fields like role, configure them elsewhere (e.g., in your user model or via plugins/hooks).

Here’s how your config should look:

export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: 'postgresql' }),
  emailAndPassword: { enabled: true },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    },
  },
  // Place additional user fields in the appropriate user model or plugin config
});

Recent Better Auth versions recommend configuring social providers using the genericOAuth plugin instead of the socialProviders key. If you want an example or help migrating to that approach, let me know see docs and PR.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 19, 2025): <!-- Greeting --> Hi @anselumjuju! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The crash happens because your config includes a non-provider key (`user`) inside `socialProviders`. Better Auth expects only supported provider keys (like `google`, `github`, etc.) in `socialProviders`, each mapping to a config object with `clientId` and `clientSecret`. When it encounters a key that isn't a known provider, it tries to call it as a function and throws the error you see [example](https://github.com/better-auth/better-auth/blob/ac00442f5c93bf86b1847f9dd4151c1fda456d4e/packages/better-auth/src/context/create-context.ts#L8-L147). To fix this, remove the `user` key from `socialProviders`. If you want to add custom user fields like `role`, configure them elsewhere (e.g., in your user model or via plugins/hooks). Here’s how your config should look: ```typescript export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql' }), emailAndPassword: { enabled: true }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, // Place additional user fields in the appropriate user model or plugin config }); ``` Recent Better Auth versions recommend configuring social providers using the `genericOAuth` plugin instead of the `socialProviders` key. If you want an example or help migrating to that approach, let me know [see docs and PR](https://github.com/better-auth/better-auth/pull/6085). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/dced9da5-ef03-441f-b403-90b7ed1b47b8?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20crash%20happens%20because%20your%20config%20includes%20a%20non-provider%20key%20%28%60user%60%29%20inside%20%60socialProviders%60.%20Better%20Auth%20expects%20only%20supported%20provider%20keys%20%28like%20%60google%60%2C%20%60github%60%2C%20etc.%29%20in%20%60socialProviders%60%2C%20each%20mapping%20to%20a%20config%20object%20with%20%60clientId%60%20and%20%60clientSecret%60.%20When%20it%20encounters%20a%20key%20that%20isn%27t%20a%20known%20provider%2C%20it%20tries%20to%20call%20it%20as%20a%20function%20and%20throws%20the%20error%20you%20see%C2%A0%5Bexample%5D%28https%3A//github.com/better-auth/better-auth/blob/ac00442f5c93bf86b1847f9dd4151c1fda456d4e/packages/better-auth/src/context/create-context.ts%23L8-L147%29.%0A%0ATo%20fix%20this%2C%20remove%20the%20%60user%60%20key%20from%20%60socialProviders%60.%20If%20you%20want%20to%20add%20custom%20user%20fields%20like%20%60role%60%2C%20configure%20them%20elsewhere%20%28e.g.%2C%20in%20your%20user%20model%20or%20via%20plugins/hooks%29.%0A%0AHere%E2%80%99s%20how%20your%20config%20should%20look%3A%0A%0A%60%60%60typescript%0Aexport%20const%20auth%20%3D%20betterAuth%28%7B%0A%20%20database%3A%20prismaAdapter%28prisma%2C%20%7B%20provider%3A%20%27postgresql%27%20%7D%29%2C%0A%20%20emailAndPassword%3A%20%7B%20enabled%3A%20true%20%7D%2C%0A%20%20socialProviders%3A%20%7B%0A%20%20%20%20google%3A%20%7B%0A%20%20%20%20%20%20clientId%3A%20process.env.GOOGLE_CLIENT_ID%20as%20string%2C%0A%20%20%20%20%20%20clientSecret%3A%20process.env.GOOGLE_CLIENT_SECRET%20as%20string%2C%0A%20%20%20%20%7D%2C%0A%20%20%7D%2C%0A%20%20//%20Place%20additional%20user%20fields%20in%20the%20appropriate%20user%20model%20or%20plugin%20config%0A%7D%29%3B%0A%60%60%60%0A%0ARecent%20Better%20Auth%20versions%20recommend%20configuring%20social%20providers%20using%20the%20%60genericOAuth%60%20plugin%20instead%20of%20the%20%60socialProviders%60%20key.%20If%20you%20want%20an%20example%20or%20help%20migrating%20to%20that%20approach%2C%20let%20me%20know%C2%A0%5Bsee%20docs%20and%20PR%5D%28https%3A//github.com/better-auth/better-auth/pull/6085%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6884)
Author
Owner

@bytaesu commented on GitHub (Dec 23, 2025):

Hi @anselumjuju, I'll look into this

@bytaesu commented on GitHub (Dec 23, 2025): Hi @anselumjuju, I'll look into this
Author
Owner

@bytaesu commented on GitHub (Dec 23, 2025):

Image

Hi @anselumjuju,

It seems there might be an issue with the settings. Please check the link below 🙂

https://www.better-auth.com/docs/concepts/database#extending-core-schema

@bytaesu commented on GitHub (Dec 23, 2025): <img width="457" height="431" alt="Image" src="https://github.com/user-attachments/assets/a3a4c936-6fa6-492c-8885-5661496ca828" /> --- Hi @anselumjuju, It seems there might be an issue with the settings. Please check the link below 🙂 https://www.better-auth.com/docs/concepts/database#extending-core-schema
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2577