Skip to content

Commit cf381a7

Browse files
os-zhuangclaude
andcommitted
fix(auth): sso() takes no schema option; bridge ssoProvider via adapter map
@better-auth/sso (1.6.20) exposes NO `schema` option (verified: no mergeSchema, runtime never reads options.schema), so the per-plugin schema-remap that oauthProvider uses is unavailable. Drop the invalid `schema` arg + the dead buildSsoPluginSchema(); call sso() bare (gated off by OS_SSO_ENABLED). Add ssoProvider -> sys_sso_provider to AUTH_MODEL_TO_PROTOCOL. KNOWN-INCOMPLETE (documented inline): the ACTIVE factory adapter (createObjectQLAdapterFactory) passes the raw better-auth model name to the data engine and maps fields only from per-model declarations — neither of which the sso plugin provides. Finishing the integration needs objectql-adapter to resolve schema-less plugin model + camelCase field names, then full E2E. Compiles green (DTS ok for plugin-auth + platform-objects); feature off by default. + pnpm-lock.yaml (@better-auth/sso ^1.6.20). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 367bbf4 commit cf381a7

4 files changed

Lines changed: 183 additions & 19 deletions

File tree

packages/plugins/plugin-auth/src/auth-manager.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
buildOrganizationPluginSchema,
2424
buildTwoFactorPluginSchema,
2525
buildOauthProviderPluginSchema,
26-
buildSsoPluginSchema,
2726
buildDeviceAuthorizationPluginSchema,
2827
buildJwtPluginSchema,
2928
buildAdminPluginSchema,
@@ -939,13 +938,15 @@ export class AuthManager {
939938
// Toggle with `OS_SSO_ENABLED` (mirrors `OS_OIDC_PROVIDER_ENABLED`).
940939
if (enabled.sso) {
941940
const { sso } = await import('@better-auth/sso');
942-
plugins.push(sso({
943-
schema: buildSsoPluginSchema(),
944-
// provisionUser / organizationProvisioning are the hook for assigning a
945-
// default env role on first federated login (ADR-0024 V1 minimal
946-
// decisions). JIT user creation works out of the box via account
947-
// linking; wire role defaults here in the follow-up.
948-
}));
941+
// NOTE: unlike `oauthProvider`, @better-auth/sso hardcodes its `ssoProvider`
942+
// model and accepts NO `schema` option (verified against 1.6.20 — no
943+
// mergeSchema, runtime never reads options.schema). Its table mapping to
944+
// `sys_sso_provider` must therefore be resolved by the better-auth adapter
945+
// / a global model map, not per-plugin here (see AUTH_SSO_PROVIDER_SCHEMA;
946+
// TODO confirm the resolved table name in E2E).
947+
// provisionUser / organizationProvisioning will assign a default env role
948+
// on first federated login (ADR-0024 V1); JIT works via account linking.
949+
plugins.push(sso());
949950
}
950951

951952
// Device Authorization Grant (RFC 8628) — for CLI / TV-style devices.

packages/plugins/plugin-auth/src/auth-schema-config.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -682,17 +682,11 @@ export const AUTH_SSO_PROVIDER_SCHEMA = {
682682
},
683683
} as const;
684684

685-
/**
686-
* Builds the `schema` option for `@better-auth/sso`'s `sso()` plugin, pointing
687-
* its single `ssoProvider` model at ObjectStack's `sys_sso_provider` table.
688-
*
689-
* @returns An object suitable for `sso({ schema: … })`
690-
*/
691-
export function buildSsoPluginSchema() {
692-
return {
693-
ssoProvider: AUTH_SSO_PROVIDER_SCHEMA,
694-
};
695-
}
685+
// NOTE: there is intentionally no `buildSsoPluginSchema()`. Unlike
686+
// `oauthProvider`, the @better-auth/sso plugin exposes NO `schema` option
687+
// (verified vs 1.6.20), so the mapping above cannot be handed to the plugin —
688+
// it must be consumed at the ADAPTER layer (AUTH_MODEL_TO_PROTOCOL + field
689+
// resolution in objectql-adapter.ts). See ADR-0024.
696690

697691
// ---------------------------------------------------------------------------
698692
// Helper: build device-authorization plugin schema option

packages/plugins/plugin-auth/src/objectql-adapter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export const AUTH_MODEL_TO_PROTOCOL: Record<string, string> = {
1616
session: SystemObjectName.SESSION,
1717
account: SystemObjectName.ACCOUNT,
1818
verification: SystemObjectName.VERIFICATION,
19+
// @better-auth/sso has NO `schema` option (verified vs 1.6.20 — no
20+
// mergeSchema, runtime never reads options.schema), so it cannot declare
21+
// its modelName/fields. Bridge the table name here. NOTE: the ACTIVE
22+
// factory adapter (createObjectQLAdapterFactory) passes the raw `model`
23+
// to dataEngine and does NOT yet consult resolveProtocolName for plugin
24+
// models — nor map sso's camelCase fields (oidcConfig→oidc_config …).
25+
// Finishing the @better-auth/sso integration needs that adapter work +
26+
// E2E (see ADR-0024 / sys_sso_provider). Off by default (OS_SSO_ENABLED).
27+
ssoProvider: 'sys_sso_provider',
1928
};
2029

2130
/**

0 commit comments

Comments
 (0)