Best practices for Next.js API architecture with external Express.js backend #72473
Unanswered
Zakisb
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Context
I've been building full-stack applications with Next.js for some time, where both the frontend and backend were unified in the same Next.js application. Recently, I'm working on an admin panel (built with Next.js) that interfaces with an existing Express.js backend server (which also serves our mobile app).
Current Setup
This new architecture presents some challenges I'd like to discuss and hear your opinions on it.
This setup currently works well for:
The Challenge
The core issue emerged when implementing Clerk authentication. The same fetchWithAuth function gets called from both server and client contexts:
1.In Server Components:
The problem is that getting the Clerk token requires different approaches based on context:
But our fetchWithAuth function doesn't know which context it's being called from!
Questions
Additional information
example of service file
Beta Was this translation helpful? Give feedback.
All reactions