You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the most interesting thing is that buffer is not in dependencies as it is just ... require('buffer') in npm library safe-buffer with 0 dependencies
Question
How to use NodeJS libraries like buffer on Remix server logic?
As this is a simple case, usually never come an issue, but any of the other libraries could cause the same issue
Additional info
Project structure:
NX
Remix (via Rollup yet - migrated from the previous version, but not entirely to Vite) for SSR, Getway to API, and some hidden from client secure/business logic handling (as BFF/middleware/proxy between Client & API)
Auth is very simple yet - JWT in httpOnly cookies managed by NestJS API (why not by Remix? Because of Single Source of Truth as we have a React-Native mobile app also)
In the case of managing jwt by Nest, Remix should only parse cookies, get token, decode it and validate it:
reason: render different UI (by e.g. lazy-loading) for different roles
Code Example
exportconstgetRole=async(request: LoaderFunctionArgs['request'],): Promise<RoleEnum>=>{const{ jwtAccessTokenName, sessionSecret }=getEnvConfig<'server'>();// Extract token from cookieconstcookie=request.headers.get('Cookie');consttoken=cookie?.split(';').find((c)=>c.trim().startsWith(`${jwtAccessTokenName}=`))?.split('=')[1];console.log('Token:',token);if(!token){// ...}// Verify token and get user Roleconstpayload=verify(token,sessionSecret);return(payloadasUserContext).role;
Some not-important details
Remix and Nest mimic 3 (Nest 4 - 1 plus for mobile app) separate Apps by subdomains (multitenant)
1 subdomain = 1 auth role
1st stage roles (Public, Admin, Manager) are fully separated
Nest manages roles separately (module/controller/db) by auth
Remix (for now) manages subdomains
User Admin can enter Manager App via admin subdomain & mixed roles
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
Issue
remix Error: Dynamic require of "buffer" is not supported
Inverstigation & solutions
remix Error: Dynamic require of "jsonwebtoken" is not supported
remix.config.cgj
->serverDependenciesToBundle
remix Error: Dynamic require of "safe-buffer" is not supported
remix Error: Dynamic require of "buffer" is not supported
package-lock.json
) didn't helpBuffer
buffer
is not in dependencies as it is just... require('buffer')
in npm librarysafe-buffer
with 0 dependenciesQuestion
How to use NodeJS libraries like
buffer
on Remix server logic?As this is a simple case, usually never come an issue, but any of the other libraries could cause the same issue
Additional info
Project structure:
versions:
TL;TR
Auth logic
Auth is very simple yet - JWT in
httpOnly
cookies managed by NestJS API (why not by Remix? Because of Single Source of Truth as we have a React-Native mobile app also)In the case of managing jwt by Nest, Remix should only parse cookies, get token, decode it and validate it:
Code Example
Some not-important details
Beta Was this translation helpful? Give feedback.
All reactions