Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.0-beta.32] Issue with Payload on an existing nextjs app while changing its admin and api paths #6402

Open
ydemetriades opened this issue May 17, 2024 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@ydemetriades
Copy link

ydemetriades commented May 17, 2024

Link to reproduction

No response

Describe the Bug

Title

[3.0.0-beta.32] Issue with Payload on an existing Next.js app while changing its admin and api paths

Environment:

  • Payload version: 3.0.0-beta.32
  • Next.js with TurboRepo

Issue Description:
I am integrating Payload CMS into an existing Next.js application that uses TurboRepo and includes multiple local packages. I've modified the admin and API paths for Payload to /center/admin and /center/api respectively. Despite these changes, I'm facing issues with user authentication, receiving 401 Unauthorized errors.

Configuration:

  • Payload configuration (payload.config.ts):

    // serverURL: process.env.NEXT_PUBLIC_SITE_URL ?? "http://localhost:3000",
    routes: {
      admin: '/center/admin',
      api: '/center/api',
    }

    I have attempted to configure serverURL, cors, and csrf settings in payload.config.ts without success.

  • Directory structure:

    .
    ├── app
    │   ├── (app)
    │   │   ├── (dashboard)
    │   │   ├── admin
    │   │   ├── api
    │   │   ├── layout.tsx
    │   │   └── layout.tsx
    │   │   └── not-found.tsx
    │   └── (payload)
    │       ├── center
    │       │   ├── admin
    │       │   └── api
    │       ├── custom.scss
    │       └── layout.tsx
    

Current Behavior:

  • Fresh database: Access to /center/admin initiates the create-first-user flow. However, the /center/api/form-state endpoint returns 401 Unauthorized errors.
  • Existing database (with an available user): The /center/api/login endpoint returns 401 Unauthorized.

Additional Information:

  • The directory structure has been adjusted multiple times to troubleshoot this issue without success.

  • I set up a new application using create-payload-app (beta.32) to isolate the issue. This new setup, detailed below, allowed me to successfully access the admin panel at /center and the API at /center/api without any authentication problems, indicating the issue may be specific to my existing application structure.

    Directory Structure of New Setup:

    .
    ├── app
    │   ├── (app)
    │   └── (payload)
    │       ├── center
    │       │   ├── admin
    │       │   └── api
    │       ├── custom.scss
    │       └── layout.tsx
    
  • For a detailed view of the original issue discussion, please visit the following Discord thread where the issue was initially discussed, providing additional insights and exchanges that might be helpful for troubleshooting.

Possible Causes:

  • There might be conflicts or overlooked configurations due to the existing routes and structure of the Next.js application that uses similar paths.
  • Potential bug with Payload's handling of non-default admin and API paths.

To Reproduce

I haven't been able to reproduce it with another existing app yet

Payload Version

3.0.0-beta.32

Adapters and Plugins

db-mongodb

@ydemetriades ydemetriades added the status: needs-triage Possible bug which hasn't been reproduced yet label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant