Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/authjs-cjs-interop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tinacms-authjs": patch
---

Fix the package outside webpack. Unwraps the CommonJS default export of `next-auth`, and stops the node entry importing the browser `tinacms` package for a single string constant. Netlify Functions, Vercel Functions and plain Node ESM previously failed to load with `(0 , import_credentials.default) is not a function`. Dropping that import also shrinks bundled backends: the Netlify Functions sample from the docs goes from 21.0 MB to 5.4 MB.
1 change: 1 addition & 0 deletions packages/tinacms-authjs/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TINA_CREDENTIALS_PROVIDER_NAME = 'TinaCredentials';
17 changes: 13 additions & 4 deletions packages/tinacms-authjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import NextAuth, { AuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { getServerSession } from 'next-auth/next';
import type { BackendAuthProvider } from '@tinacms/datalayer';
import { TINA_CREDENTIALS_PROVIDER_NAME } from './tinacms';
import NextAuthImport, { AuthOptions } from 'next-auth';
import { getServerSession } from 'next-auth/next';
import CredentialsImport from 'next-auth/providers/credentials';
// Not from './tinacms': that entry pulls the browser `tinacms` package into the
// node build, and Node's ESM loader cannot resolve its transitive imports.
import { TINA_CREDENTIALS_PROVIDER_NAME } from './constants';

// next-auth v4 is CommonJS: webpack unwraps its `__esModule` default but Node's
// ESM loader and esbuild do not, breaking every non-Next.js backend. See #7434.
const interopDefault = <T>(mod: T & { default?: T }): T => mod.default ?? mod;

const NextAuth = interopDefault(NextAuthImport);
const CredentialsProvider = interopDefault(CredentialsImport);

const authenticate = async (
databaseClient: any,
Expand Down
3 changes: 2 additions & 1 deletion packages/tinacms-authjs/src/tinacms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
} from 'next-auth/react';
import { AbstractAuthProvider } from 'tinacms';
import type { FC } from 'react';
import { TINA_CREDENTIALS_PROVIDER_NAME } from './constants';

export const TINA_CREDENTIALS_PROVIDER_NAME = 'TinaCredentials';
export { TINA_CREDENTIALS_PROVIDER_NAME };

export class DefaultAuthJSProvider extends AbstractAuthProvider {
readonly callbackUrl: string;
Expand Down
103 changes: 60 additions & 43 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ catalog:
parse-entities: 4.0.1
picomatch: ^4.0.2
picomatch-browser: 2.2.6
postcss: ^8.5.16
postcss: ^8.5.23
postcss-import: ^14.1.0
postcss-nesting: ^10.2.0
prettier: ^2.8.8
Expand Down
Loading
Loading