Skip to content

Import Map does not accept AzureAD provider from NextAuth #10958

Open
@mariovalney

Description

@mariovalney

Describe the Bug

When running the command:

yarn run payload generate:importmap

The default pages/api/auth/[...nextauth].js file, which imports AzureAD from NextAuth:

import AzureAD from 'next-auth/providers/azure-ad';

throws the following error:

TypeError: AzureAD is not a function

Expected behavior:
I understand that authentication outside of Payload CMS is not the standard approach, but in my use case, I need to handle authentication separately. This error could potentially affect other functions in similar scenarios, making it an issue worth checking.

Workaround/Fix:
To bypass the issue, I modified the provider initialization as follows:

const AzureADProvider = (typeof AzureAD === 'function') ? AzureAD : (a) => a;

const options = {
  debug: (process.env?.NEXT_AUTH_DEBUG || '0') === '1',
  providers: [
    AzureADProvider({
      clientId: process.env.AZURE_AD_CLIENT_ID || '',
      clientSecret: process.env.AZURE_AD_CLIENT_SECRET || '',
      tenantId: process.env.AZURE_AD_TENANT_ID,
// ...

Additional context:
This issue might be related to ESM/CJS compatibility in [next-auth/providers/azure-ad](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/azure-ad.ts#L22). Perhaps the import should be handled differently in the import map.

Link to the code that reproduces this issue

NONE

Reproduction Steps

  1. Install next-auth and add azure-ad provider.
  2. Run yarn run payload generate:importmap.
  3. Observe the error.

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

Binaries:
  Node: 23.3.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.20.0
  next: 15.1.6
  @payloadcms/db-postgres: 3.20.0
  @payloadcms/email-nodemailer: 3.20.0
  @payloadcms/graphql: 3.20.0
  @payloadcms/next/utilities: 3.20.0
  @payloadcms/payload-cloud: 3.20.0
  @payloadcms/richtext-lexical: 3.20.0
  @payloadcms/translations: 3.20.0
  @payloadcms/ui/shared: 3.20.0
  react: 19.0.0-rc-69d4b800-20241021
  react-dom: 19.0.0-rc-69d4b800-20241021
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32503
  Available CPU cores: 8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions