Google Oauth Scopes Error

src/lib/auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { prisma } from "./prisma";

export const auth = betterAuth({
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            // Request scopes needed for Google Docs reading:
            scope: "openid email profile https://www.googleapis.com/auth/documents.readonly https://www.googleapis.com/auth/drive.metadata.readonly",
        },
    },
    database: prismaAdapter(prisma, {
        provider: "postgresql",
    }),
    user: {
        additionalFields: {
            education: { type: "string", required: false },
            school: { type: "string", required: false },
            onboardingCompleted: {
                type: "boolean",
                required: false,
                defaultValue: false,
            },
        },
    },
});


Error:
Some requested scopes were invalid. {valid=[https://www.googleapis.com/auth/userinfo.email, https://www.googleapis.com/auth/userinfo.profile, openid], invalid=[a, c, d, e, f, g, h, i, l, m, n, ., o, /, p, r, s, t, u, v, w, y, :]} Learn more about this error
If you are a developer of SparkStudy, see error details.
Error 400: invalid_scope


Error 400: invalid_scope
Request details: flowName=GeneralOAuthFlow


This was working before adding the https://www.googleapis.com/auth/documents.readonly and https://www.googleapis.com/auth/drive.metadata.readonly scopes
Screenshot_2025-03-26_at_8.58.56_PM.png
Solution
you should pass scopes as an array of string instead
Was this page helpful?