Google LinkSocial Additional Scopes

Hello! I am using Google Oauth as a provider and attempting to follow the documentation to allow users to add calendar scopes after the login, the below correctly adds scopes, but once a user logs in with the standard oauth again that overwrites the additional scopes. I've been trying to debug this for a bit but can't figure out if there is supposed to be standard better-auth management for this or if I need to add some hook to the database to make sure we don't overwrite the scopes. Tahnk you!
{typescript}
await authClient.linkSocial({
provider: "google",
scopes: ["https://www.googleapis.com/auth/calendar"],
});
{typescript}
await authClient.linkSocial({
provider: "google",
scopes: ["https://www.googleapis.com/auth/calendar"],
});
{typescript}
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db";
import * as schema from '../db/schema';

if (!process.env.BETTER_AUTH_SECRET) {
throw new Error('BETTER_AUTH_SECRET environment variable is not set');
}

export const auth = betterAuth({
// Add secret for encryption and session handling
secret: process.env.BETTER_AUTH_SECRET,

// Database configuration
database: drizzleAdapter(db, {
provider: 'pg',
// Map model names to schema objects using lowercase to match schema definitions
schema: {
user: schema.user,
session: schema.session,
account: schema.account,
verification: schema.verification
}
}),

// Account configuration
account: {
modelName: "account",
accountLinking: {
enabled: true, // Enable account linking
trustedProviders: ["google"], // Consider Google a trusted provider
}
},

// OAuth providers
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}
},

// OMMITTING EXTRA CODE DUE TO LIMIT

// Next.js integration
plugins: [nextCookies()]
});
{typescript}
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db";
import * as schema from '../db/schema';

if (!process.env.BETTER_AUTH_SECRET) {
throw new Error('BETTER_AUTH_SECRET environment variable is not set');
}

export const auth = betterAuth({
// Add secret for encryption and session handling
secret: process.env.BETTER_AUTH_SECRET,

// Database configuration
database: drizzleAdapter(db, {
provider: 'pg',
// Map model names to schema objects using lowercase to match schema definitions
schema: {
user: schema.user,
session: schema.session,
account: schema.account,
verification: schema.verification
}
}),

// Account configuration
account: {
modelName: "account",
accountLinking: {
enabled: true, // Enable account linking
trustedProviders: ["google"], // Consider Google a trusted provider
}
},

// OAuth providers
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}
},

// OMMITTING EXTRA CODE DUE TO LIMIT

// Next.js integration
plugins: [nextCookies()]
});
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?