feat(socialLink): add support for custom scopes in social account linking (#2074)

* feat(socialLink): add support for custom scopes in social account linking

- Updated documentation to include information on requesting specific scopes when linking social accounts.
- Added a test case to verify that custom scopes are correctly passed to the authorization URL.
- Modified the account linking endpoint to accept additional scopes as an optional parameter.

* chore: lint

* fix(account): update account linking logic and tests

---------

Co-authored-by: Bereket Engida <bekacru@gmail.com>
This commit is contained in:
Léo LEDUCQ
2025-04-11 12:54:30 +02:00
committed by GitHub
parent 8643cb6d13
commit c14f127fd3
6 changed files with 114 additions and 33 deletions

View File

@@ -304,6 +304,16 @@ Users already signed in can manually link their account to additional social pro
});
```
You can also request specific scopes when linking a social account, which can be different from the scopes used during the initial authentication:
```ts
await authClient.linkSocial({
provider: "google",
callbackURL: "/callback",
scopes: ["https://www.googleapis.com/auth/drive.readonly"] // Request additional scopes
});
```
If you want your users to be able to link a social account with a different email address than the user, or if you want to use a provider that does not return email addresses, you will need to enable this in the account linking settings.
```ts title="auth.ts"
export const auth = betterAuth({