[PR #8020] [CLOSED] Fix(sso): handle samlify CJS/ESM interop runtime error #15938

Closed
opened 2026-04-13 10:19:00 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8020
Author: @GautamBytes
Created: 2/17/2026
Status: Closed

Base: canaryHead: fix-sso-spmetadata-esm-interop


📝 Commits (2)

  • 31533b8 fix(sso): handle samlify ESM interop for SPMetadata
  • b3b7ca1 fix(sso): apply samlify ESM interop shim to all imports

📊 Changes

4 files changed (+18 additions, -6 deletions)

View changed files

📝 packages/sso/src/index.ts (+4 -1)
📝 packages/sso/src/routes/helpers.ts (+4 -1)
📝 packages/sso/src/routes/sso.ts (+4 -1)
📝 packages/sso/src/saml.test.ts (+6 -3)

📄 Description

Summary

Fixes #7993 - saml.SPMetadata is not a function runtime error when using samlify in ESM environments.

Problem

Some bundlers/runtimes wrap CJS module.exports under .default when importing via import * as saml from "samlify". This causes all samlify exports (SPMetadata, ServiceProvider, IdentityProvider, etc.) to be undefined at runtime.

Solution

Added a module-level interop shim in both sso.ts and helpers.ts:

import * as _saml from "samlify";
const saml = ((_saml as any).default ?? _saml) as typeof _saml;

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fix samlify CJS/ESM interop to prevent the saml.SPMetadata is not a function runtime error in ESM builds. Applies the import shim to all samlify imports across sso.ts, helpers.ts, index.ts, and tests, and updates test cases to validate both provided and generated SP metadata paths.

<sup>Written for commit b3b7ca1d5fc253f9edb88c6ca4683d02adbd9aac. Summary will update on new commits.</sup>

<!-- End of auto-generated description by cubic. -->



---

<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8020 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 2/17/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix-sso-spmetadata-esm-interop` --- ### 📝 Commits (2) - [`31533b8`](https://github.com/better-auth/better-auth/commit/31533b841a1fe71dc6e44f71f5d3fd7865b41cd7) fix(sso): handle samlify ESM interop for SPMetadata - [`b3b7ca1`](https://github.com/better-auth/better-auth/commit/b3b7ca1d5fc253f9edb88c6ca4683d02adbd9aac) fix(sso): apply samlify ESM interop shim to all imports ### 📊 Changes **4 files changed** (+18 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/index.ts` (+4 -1) 📝 `packages/sso/src/routes/helpers.ts` (+4 -1) 📝 `packages/sso/src/routes/sso.ts` (+4 -1) 📝 `packages/sso/src/saml.test.ts` (+6 -3) </details> ### 📄 Description ## Summary Fixes #7993 - `saml.SPMetadata is not a function` runtime error when using samlify in ESM environments. ## Problem Some bundlers/runtimes wrap CJS `module.exports` under `.default` when importing via `import * as saml from "samlify"`. This causes all samlify exports (`SPMetadata`, `ServiceProvider`, `IdentityProvider`, etc.) to be `undefined` at runtime. ## Solution Added a module-level interop shim in both `sso.ts` and `helpers.ts`: ```typescript import * as _saml from "samlify"; const saml = ((_saml as any).default ?? _saml) as typeof _saml; <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix samlify CJS/ESM interop to prevent the “saml.SPMetadata is not a function” runtime error in ESM builds. Applies the import shim to all samlify imports across sso.ts, helpers.ts, index.ts, and tests, and updates test cases to validate both provided and generated SP metadata paths. <sup>Written for commit b3b7ca1d5fc253f9edb88c6ca4683d02adbd9aac. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:19:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15938