4,659 questions
Best practices
0
votes
0
replies
18
views
Next.js multi-domain (multi-tenant) site: resolve business in middleware vs in layout/server component?
I have a Next.js customer-facing website that can be reached by many different domains. Each domain represents a different business, and depending on the domain we need to load that business’s content ...
-1
votes
0
answers
38
views
How to protect routes in Next.js when auth tokens are stored in HttpOnly cookies? [closed]
I’m using Next.js (App Router) where authentication is handled by the backend.
The backend sets access and refresh tokens in HttpOnly + Secure cookies, so the frontend cannot read token values (which ...
1
vote
1
answer
137
views
Use middleware except if auth user is admin
I have a small app where users have to subscribe to post topics.
I use Laravel Cashier with Stripe and it works fine.
I have created a middleware to check if auth::user() is subscribed or not :
public ...
1
vote
1
answer
112
views
Passing user data from NextJS middleware to the client component
I want to pass the data from the NextJS middleware to the client component. I am using NextJS for the frontend, and an Express API for the backend.
I could do it with X-Headers but what I want to send ...
Best practices
0
votes
3
replies
74
views
Apply [ApiController] to all controllers implicitly
Adding [ApiController] on a controller class has various benefits. Especially the automatic model validation and problem details parts.
The problem with this attribute is that it's easy to forget to ...
1
vote
0
answers
54
views
Bun + Express on Vercel: How to Modularize Routes from Separate Files?
I'm deploying a Bun + Express application to Vercel. Locally, my Express app works perfectly with routes defined in separate files and imported into index.ts. However, on Vercel, the deployment ...
Advice
0
votes
0
replies
60
views
How to properly build an HR Management System using Laravel (API) + Next.js (frontend) with token authentication and middleware?
I'm building an HR Management System using:
Backend: Laravel
Frontend: Next.js
Authentication(SPA): Laravel Breeze (already set up for backend)
I'm a beginner in Next.js, and I’m a bit stuck on how ...
1
vote
1
answer
92
views
Zustand persist doesn't execute in testing
I am doing unit testing for my project.
This is the code I want to test:
import { create } from "zustand";
import { persist } from "zustand/middleware";
interface LanguageState {
...
-4
votes
1
answer
75
views
How to restrict routes in next js
I need want to send the only authenticated user to the /chat route in next js how to do ut using the middleware? Although I created a middleware and place it inside the root folder it dosen't detect ...
2
votes
1
answer
102
views
Why i cannot set property userId on this function?
I’m building an authentication system with Express + JWT + Cookie.
I have a middleware userAuth that decodes the token and puts the userId into req.body.
Here is the code:
import jwt from "...
2
votes
1
answer
161
views
Trying to write a unit test to test a fastapi app with a middleware that changes the request.url.path
This is the code below. I want to test a request coming in that has part of its path prefixed by external means. This middleware removes it before servicing the request.
app = FastAPI(
title="...
0
votes
0
answers
57
views
Session token/headers not detected in production (Vercel)
When deployed, it fails
Cookie validation
Bypass Vercel firewall rules for API routes
even though cookie + header is seen from the browser
middleware.ts
import { NextResponse } from 'next/server';
...
0
votes
0
answers
57
views
Can't access headers.origin in NextJS middleware (App router)
I'm trying to follow the basic tutorial provided by NextJS to setup a middleware for my API. When trying to restrict origin (for testing purposes) to http://localhost:3000, the request.headers.get('...
0
votes
2
answers
314
views
Middleware not triggering in Next.js app using next-auth
I’m working on a Next.js 14 app with the App Router and next-auth@5. I followed the official Next.js Learn guide on authentication, except I replaced email with username in the database.
I set up ...
0
votes
1
answer
193
views
Difference between RequestDelegate and Middleware in ASP.NET Core?
I was recently in a technical discussion with a senior developer and was asked:
What is the difference between RequestDelegate and Middleware in ASP.NET Core?
I have already visited the following ...
2
votes
1
answer
227
views
How to get remaining ASP.NET Core session expiry time to return it to the client?
I'm working on an ASP.NET Core Web API where I use session middleware with a configured idle timeout, e.g.:
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(20);
});
...
0
votes
1
answer
123
views
$request->getAttribute('fe_user') returns NULL in Typo3 v13
I'm new to TYPO3 v13 and am currently trying to write a small login middleware, really simple at first. But somehow I can't get any further with $request->getAttribute(‘fe_user’). It always returns ...
1
vote
0
answers
24
views
How to integrate Apitally middleware in LoopBack 4 so it applies to all API routes?
This setup only seems to work when I update or refresh my OpenAPI (Swagger) spec. When I call real API endpoints, apitallyRouter middleware doesn’t get triggered at all (no logs, no requests sent to ...
1
vote
0
answers
242
views
Internal server error "Cannot read properties of undefined" during Google OAuth
I created authentications using Better-Auth and Google as the auth client. I have the correct URL for the authorized JavaScript origins and for the authorized redirect URL and I believe my set up is ...
0
votes
1
answer
277
views
Why is auth:sanctum used on api routes and not on web routes?
I am using Laravel sanctum SPA auth to protect my routes/api.php routes. Instead of manually implementing the routes and controllers for authentication, I am using Laravel Fortify.
Now Fortify adds ...
0
votes
0
answers
59
views
How to configure middleware to run and be debugged in next.js
Ultimately, I want to route requests to pages within subdomains in my next.js application. If I specify the correct subdomain in a route, I believe that I need to have a middleware.ts file under the ...
0
votes
1
answer
82
views
How to implement lazy initialization of authjs config in nextjs?
How to implement lazy initialization of authjs (v5 beta) config in nextjs 14 without encountering the error Error: The Middleware "/src/middleware" must export a middleware or a default ...
0
votes
1
answer
130
views
What is the difference between ctx.AbortWithStatusJSON() and ctx.JSON() methods in golang GIN
What is the difference between the methods ctx.AbortWithStatusJSON() and ctx.JSON()? As I understand it, the first one calls TWO methods inside itself - Abort(), which interrupts the processing of the ...
2
votes
1
answer
140
views
Is this safe when it come to prevent requests from outside the own website?
I am intending to specify the single origins where I want my different endpoints to receive requests from. After looking at different options I thought that this might be the simplest way, and it ...
1
vote
1
answer
202
views
Get routing group programmatically in middleware using Next.js
Next.js allows you to create routing groups to organize your project. I would like to use this information in a middleware to distinguish private groups that need authentication from public routes. E....
-1
votes
1
answer
67
views
redux thunk pattern composing middleware calls
I'm sure this has been asked and answered, but maybe I'm not able to phrase it correctly to find the right results.
Say I have two redux middleware operations:
a call to create an asset entity in the ...
3
votes
2
answers
9k
views
How to correctly configure CORS in Laravel 12.13 with the HandleCors middleware in bootstrap/app.php?
I am currently working with Laravel 12.13 and facing an issue with CORS. I have configured the HandleCors middleware and the CORS settings in my application, but I am still getting CORS errors when ...
1
vote
1
answer
65
views
vercel not redirecting to previous page
user redirected to login page after a trying to access a protected page. I am storing the protected page url in search params and after login redirect to that page. (my approach works on localhost ...
0
votes
0
answers
113
views
Next.js Middleware Error: "Cannot read properties of undefined (reading 'substring')" in oidc-token-hash
I'm implementing authentication middleware in a Next.js (v13+) application using NextAuth.js, and I'm encountering an error when trying to validate the session token. The error occurs in the oidc-...
0
votes
1
answer
97
views
Why does setting CultureInfo.CurrentUICulture and using RequestCultureFeature not change the language in ASP.NET Core?
I'm working on an ASP.NET Core web application with custom localization using JSON files. I'm trying to change the language at runtime and reflect it immediately in the current request. Here's what I ...
0
votes
1
answer
138
views
Next.JS middleware causes delay in navigation
I'm building my web app with Next.JS and React JS. I'm currently using middleware for some tasks like checking user's authentication while accessing the URL and refreshing tokens if needed. However, I ...
0
votes
1
answer
90
views
JWT Token is set in cookies but is always undefined in Next.js middleware
I'm facing an issue in my Next.js 15 application.
I am setting the jwtToken in the cookies when a user logs in. I have verified this through the browser's Application tab in the developer tools, where ...
0
votes
1
answer
80
views
Accessing cookies in middleware nextjs
Hello I want to add a middleware to implement a filter request in my frontend.
Basically the workflow is the following:
User login in page localhost:3000/auth
Backend replies ok with access_token set ...
0
votes
1
answer
51
views
middleware doesn't recognize session when using server actions
after some work i found out that when using server actions to hit some route handler the session will be undefined because server actions run on the server without a request context from the browser, ...
0
votes
1
answer
248
views
Azure Durable Functions not working with Custom Middleware
I have an Azure Durable Function that worked before I added custom middleware. Do Azure Functions work with custom middleware?
I've added the middleware to manage custom authentication and to ...
0
votes
1
answer
209
views
Next.js Middleware: URL rewrite works in development but doesn't work in production
OBS: text translated with the help of AI
I am trying to use a middleware in Next.js to rewrite the URL for a subdomain (like dividas.dominio.com) to /dividas. The behavior works correctly in the ...
0
votes
0
answers
35
views
Next.JS middleware & front-end cookie synchronization
My team and I are building a web app with Next.JS, and we are mainly working on Front-end. The back-end was already implemented with another language because it's shared with our mobile apps.
Now I'm ...
1
vote
2
answers
153
views
Express Req.Query initialization remains empty
I have this alias middleware which supposed to manually initialized the queries.
exports.aliasTopTours = (req, res, next) => {
req.query.limit = '5';
req.query.sort = '-ratingsAverage,price';
...
0
votes
1
answer
441
views
Handling Expired Access Tokens in Next.js Services with Refresh Token Logic
I’m working on a front-end project using Next.js 15, where the backend is separate and responsible for user authentication. The flow is as follows: I send the user credentials (email and password) ...
0
votes
0
answers
29
views
Empty HTTP POST request going unhandled in Express.js server
I have an Ubuntu image based docker container working as a development environment. Inside this container, I have my express app. Below are the code files.
// Start the Express Server - index.ts
...
0
votes
2
answers
70
views
How to implement after middleware in slim 4 php framework
I am following the documentation of slim 4 middleware at Docs
I was able to implement the before middleware. But not sure how to implement after middleware. It says the DI should be used but the code ...
0
votes
2
answers
62
views
IStartupFilter for exception handling in .NET integration tests not capturing the exceptions
I have an integration test using a WebapplicationFactory in .Net 9 to spin up the main Program.cs and hit endpoints. My problem is often an endpoint will return a generic 500 error when an unhandled ...
0
votes
1
answer
56
views
Scrapy CrawlOnce Middleware: struct.error: unpack requires a buffer of 4 bytes on Job Restart
I'm using Scrapy's built-in CrawlOnce middleware, and when I stop and restart a job, I sometimes get this error:
Traceback (most recent call last):
File "/app/tasks/crawl.py", line 250, in ...
0
votes
0
answers
20
views
NextJS midleware flow of cookies / headers
I have a confusing situation with NextJS and session cookies and middleware, the flows are:
New user hits site -> middleware creates a new anon session token and sets the set cookie header in the ...
0
votes
0
answers
48
views
Catch HTTPException raised in route [duplicate]
Need to catch HTTPException raised in route in middleware.
Raise exception in route:
@worker.get("/v1/error_400")
async def error_400():
raise HTTPException(
status_code=400,
...
0
votes
0
answers
22
views
Auth middleware fails to check for the session
I have multiple middlewares at the same file, if user is not logged in; the auth middleware will redirect user to login page, the problem is even when user is logged in it will return login page ...
1
vote
1
answer
2k
views
How to apply a global rate limit for all routes using SlowAPI and FastAPI?
I want to configure rate limiting with SlowAPI (in-memory, without Redis Cache etc.), but I don't want to add the @limiter.limit() decorator seperately for every endpoint.
So, something I don't want ...
0
votes
1
answer
68
views
Any way to customize token endpoint when using Microsoft.AspNetCore.Authentication.OpenIdConnect middleware in ASP.NET Core
I'm trying to authenticate using an identity provider that has its token endpoint on /profile/oidc/token instead of the usual /oauth/token endpoint. Is there any way to customize this? I'm always ...
0
votes
0
answers
19
views
NextAuth authorize method not allowing usage of MongoDB queries in NextJs
Intro
Hello, I am using the following files for my NextAuth configuration. When I use a server action inside the authorize method I get the edge error. I tought that the authorize method does not run ...
1
vote
2
answers
165
views
Best way to update user infos in frontend from stripe webhook
I am currently finalizing a payment system in my ReactJS - FastAPI web app, and I'm facing a problem.
Indeed, I use stripe for payments and I use the stripe webhooks system to update the user infos in ...