Questions tagged [next-connect]
35 questions
4
votes
2 answers
Override request type in next-connect middleware
I'm using next-connect with next.js & typescript, and I want to create a middleware that adds some fields to request object and infer the new request type. The code below:
// multipart middleware
export type NextApiRequestMultipart = NextApiRequest…

Ismail_Aj
- 332
- 1
- 4
- 17
4
votes
1 answer
Next.js routing with "next-connect" for subroutes
In my Next.js project, I created an express like route->middleware->endpoint pattern using next-connect package.
I have this route pattern:
/api/tours
/api/tours/:id
/api/tours/top-5-cheap
/api/tours/stats
/api/tours/monthly-plan
...
In my…

ABDULLOKH MUKHAMMADJONOV
- 4,249
- 3
- 22
- 40
4
votes
1 answer
How to handle errors inside getServerSideProps in Next.js using next-connect
I'm using Next.js and next-connect to handle middlewares.
But I'm having problems trying to handle errors when I use several middlewares inside getServerSideProps.
This is the code I have inside getServerSideProps, I just created a handler using…

giorgiline
- 1,271
- 4
- 21
- 35
4
votes
4 answers
Multer doesn't return req.body and req.file using next-connect
I'm using nextjs and I want to upload a file so I used next-connect in order to use multer
import nc from "next-connect";
import multer from "multer";
export const config = {
api: {
bodyParser: false,
},
}
const upload = multer({…

Eye Patch
- 881
- 4
- 11
- 23
3
votes
2 answers
Server Error TypeError: (0 , next_connect__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
I've got this error while using next-connect package.(i'm following a guy on youtube)
here's my code
import nc from 'next-connect';
import Product from '../../../models/Product';
import db from '../../../utils/db';
const handler =…

wail
- 55
- 2
- 10
3
votes
0 answers
How do I test a next js api route which uses next-connect?
I followed this article here, to try testing a simple api route in Next.js.
This article uses node-mocks-http to mock req and res objects.
It works with normal next api (which doesn't use next-connect, eg. described in the article above), but when I…

Lokenath Karmakar
- 103
- 1
- 8
2
votes
0 answers
'next-connect' error (nextConnect is undefined)
I am trying to integrate 'next-connect' into my Nextjs app in order to use multer inside of my middleware. I cannot import multer using the Nextjs built-in middleware feature (the one where you create a separate 'middleware.js' file). However, when…

Joey Kyber
- 77
- 5
2
votes
0 answers
Pass next-auth session to prisma via nexus
I'm wondering on how to pass the next-auth session as context to my nexus queries. The reson behind is that I want the sessions email to retrieve data from my database with nexus. I'm also using Apollo Server and next-connect here.
Here's what I…

Felix Haeberle
- 1,530
- 12
- 19
2
votes
2 answers
Next.js getting mixed up API responses
I'm trying to develop my first application with Next.js, and there's something happening that is really bothering me.
My app makes 2 requests after first loading, /api/me and /api/feed
My component fetches the data like this:
useEffect(() => {
…

iagowp
- 2,428
- 1
- 21
- 32
1
vote
1 answer
Next-connect error : unable to use next-connect for routing in my next.js project with javascript
My next version is 13.4.5 (latest)
My next-connect version is 1.0.0 (latest)
In pages>api>auth>signup.js :
import { createRouter } from "next-connect"
const handler = createRouter()
handler.post(async (req, res) => {
res.send("Welcome from the…

Riyan Ali
- 11
- 2
1
vote
0 answers
NextConnect use a middleware inside another
I have an auth middleware that I want to use it's logic to develop other middlewares (ie: adminMiddleware, receptionMiddleware ...)
// adminMiddleware.ts
const authMiddleware = async (
req: NextApiRequest,
res: NextApiResponse,
next:…

Ismail_Aj
- 332
- 1
- 4
- 17
1
vote
1 answer
Undefined connection string from non browser exposed environment variable MongoDB & NextJS (next-connect)
I'm having a problem with my mongodb connection string in my nextjs CRUD application in production.
I followed this guide: https://www.mongodb.com/developer/how-to/nextjs-building-modern-applications/
And I read about environment variables here:…

Rekkert
- 43
- 5
1
vote
0 answers
Client side data fetching with SWR from internal API route
I'm trying to fetch the data i get to an API route in my Next.js app but it doesn't work.
Here's my code on my API route where i get the data:
import nc from "next-connect";
const jobHandler = nc();
jobHandler.get((req, res) => {
…

Ilir
- 488
- 5
- 20
1
vote
1 answer
CORS error when trying to redirect from http://localhost:3000 to https://api.twitter.com in Next.js using next-connect?
I am trying to get redirect to work but always get bombarded with an error in console saying:
Access to fetch at 'https://api.twitter.com/oauth/authenticate?oauth_token=' (redirected from 'http://localhost:3000/api/auth/twitter/generate-auth-link')…

deadcoder0904
- 7,232
- 12
- 66
- 163
1
vote
1 answer
Next js: Error middleware is returning res.status is undefined
I am using next-connect in my next.js app to run server side code. I am using custom error middleware but it is throwing error as
res.status is undefined
This is my error middleware
export const errorMiddleWare = (err, req, res, next) => {
…

Nick
- 103
- 9