Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

authenticate.admin(request) server error

authenticate.admin(request) server error

lili99
Shopify Partner
2 0 0

Issue Summary

Environment:

  • App Framework: Shopify App with Remix template
  • Database: PostgreSQL (Previously SQLite, recently migrated)
  • Deployment: The app functions correctly in the local environment but encounters issues in production.
  • Error Encountered: When calling authenticate.admin(request), a 500 server error is returned in production, while it works as expected locally.
  • Postman Testing: The request to authenticate.admin(request) returns a 200 response in Postman.

Relevant Logs from Production:

  • Shopify logs indicate
    [shopify-app/INFO] Authenticating admin request
    [shopify-app/INFO] No valid session found
    [shopify-app/INFO] Requesting offline access token
    size: 0, [Symbol(Body internals)]: { body: null, type: null, size: 0, boundary: null, disturbed: false, error: null }, [Symbol(Response internals)]: { url: undefined, status: 500, statusText: 'Internal Server Error', headers: {}, counter: 0, highWaterMark: undefined } }

  • Steps Taken to Debug
  1. Verified Database Connectivity:

    • The production database is accessible as I can connect to it when running the app locally.
    • Prisma client configuration was reviewed and confirmed to be accurate.
    • Database connection was tested, confirming accessibility in production.
  2. Session Storage and Prisma Configuration:

    • The Prisma Session model is defined in the sessions schema with proper configuration.
    • Schema:
      prisma
       
      model Session { id String @Id shop String state String isOnline Boolean @Default(false) scope String? expires DateTime? @db.Timestamp() accessToken String userId BigInt? @@schema("sessions") }
    • Prisma Client logs were enabled for query, info, warn, and error levels to track database interactions and identify if the session creation or retrieval process was problematic.
    • Observed that the error occurred before any attempt to create or retrieve a session in the Prisma database.
  3. Confirmed Postman Compatibility:

    • A manual request to the endpoint via Postman returned a 200 response, confirming that the endpoint itself functions as expected when called independently.
  4. Examined CORS and Authentication Flow:

    • Verified that the app correctly handles authentication and makes requests according to Shopify’s requirements.
    • Compared request headers and payload between Postman and the app to ensure consistency.
    • Reviewed CORS settings to ensure there are no issues with cross-origin requests.
  5. Captured and Reviewed Detailed Logs:

    • Logged request headers, payloads, and responses in the app to capture all steps leading up to the error.
    • Enabled Prisma Client’s debug mode to capture database-related issues, though no anomalies were found.
  6. Error Consistency:

    • The issue consistently occurs in production when making the authenticate.admin(request) call, regardless of the request source.
Replies 0 (0)