Why is the form data not being added to the object sent to MongoDB cloud, resulting in an empty object being sent? Hard coding values manually works: This posts an empty object {}: const formData = new FormData({ firstName: firstName, lastName: ...
TLDR; A middleware similar to express for Next.js where I can define it once and have it automatically apply to all routes. I am looking for a middleware style like what we have in express. Ideally, I would define the middleware in the server.js (entry f ...
A simplified representation of my code utilizing two different approaches. from fastapi import FastAPI middleware = [ Middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=False, allow_methods=["*"], ...
My Nuxt app includes this middleware function: middleware(context) { const token = context.route.query.token; if (!token) { const result = await context.$api.campaignNewShare.createNewShare(); context.redirect({'name': 'campaigns-n ...
About the Issue: I am currently using Next.js version 14.0.4 for a web application, and I have encountered a problem with browser navigation following user logout. The issue arises when a user logs out and then tries to navigate back using the browser&apos ...
I've been working on implementing route protection using Next.js 12 middleware function, but I keep encountering an issue where every time I try to access the session, it returns null. This is preventing me from getting the expected results. Can anyone ...
I am having issues with button visibility based on user authentication in my MySQL and EJS setup. connection.js const mysql = require('mysql'); const util = require('util'); require('dotenv').config(); const connection = mysql.createConnection({ host ...
Is there a way to restrict access to middleware in Next.js so that only mobile devices can access it? I need to handle certain DOM elements for a webview app, but for desktop web, I want them to go directly to the index page without passing through the mid ...
Within my Express.js application, I have integrated custom validations and parameter parsing. Specifically, one of my routes requires the obj_id to be included in the route. In cases where mongoose cannot locate an object with that ID in the database, a 40 ...
Once the cookie is set, I am unable to retrieve it in the middleware without having to refresh the page first. Why does this occur? The cookie is being set as shown below: import { getCookies, setCookie, deleteCookie, hasCookie } from 'cookies-next&a ...
Currently, I am in the process of developing an app with express and have created a function to set a language cookie. [..] app.use(cookieParser()); app.use(function(req, res, next) { if(req.cookies.lang === undefined){ console.log(req.cookies); ...
import type { NextFetchEvent, NextRequest } from "next/server"; import { getSession } from "next-auth/react"; import { NextResponse } from "next/server"; export async function middleware(req: NextRequest, ev: NextFetchEvent) ...
I am seeking guidance on how to handle routing for multi-language URLs in Node.js, Currently, I have the following routes set up where each language generates specific routes as shown below. However, with more than 5 languages, efficiency is becoming a co ...
While constructing a website with next14, storyblok, and i18n, I encountered an issue in the browser related to the automatic Google translate feature for Georgian and English languages. Despite setting Georgian as the default language in my app, when swit ...
Introduction Within my API, it is essential to authenticate the caller following input validation. The authorization for certain endpoints relies on details provided in the input parameters, such as the specific server-side resource being accessed and the ...
I am looking to enhance my application by creating a middleware that will automatically format the output and return it in a structured format. The desired format is as follows: { "successful": "true", "message": "Successfully created", "data": { ...
Currently in the process of developing a REST API using Express and Typescript, I am encountering difficulties when trying to extend the Request/Response objects of Express. Although my IDE shows no errors, Typescript throws TS2339 Errors during compilati ...
Encountering an issue when trying to send form-data in postman as Sequelize returns an error: value cannot be null However, everything works fine when sending a raw request with JSON. Have tried using body-parser and multer, but no luck. This is my inde ...
I'm facing some challenges with implementing Passport for authentication. I have set up my signup strategy in the following way: passport.use('local_signup', new localStrategy({ usernameField: 'username', passwordField:'password', passReqToCallba ...
I am currently troubleshooting an issue in my straightforward express backend boilerplate. I have a universal middleware that should execute with each and every request hitting the server (specifically, I am aiming to establish a cookie). const express = ...
I'm facing a challenge with express and middleware. My goal is to serve an image from disk, but if it's not there, download it from an external server and then display it. Subsequent requests for the same image should be served from disk. Downlo ...
As a beginner in the world of node and express, I am delving into exploration. Recently, I created two middleware functions each with its own mount path. Surprisingly, MIDDLEWARE 2 is being invoked even when the incoming request is not intended for it. ...
I want to ensure basic error handling is implemented on every route, so that the API always responds with a 500 error in case of exceptions. Even though this pattern suggests using a try/catch block in each route: app.post('/post', async (req, r ...
Imagine a scenario where we have a REST API with the following route: app.put("/users/:userId", verifyUser, isOwner, updateUser); In this setting, there are multiple ways things can go wrong. The user may lack authorization due to not being logged in or ...
Here's the code snippet from my /pages/api/_middleware.js file: import { getSession } from '@auth0/nextjs-auth0' export default async function middleware(req, ev) { const session = await getSession(req) console.log(session) return NextResponse ...
I am starting to learn nodejs and express, and while reviewing some code I found this interesting snippet. Can someone please explain what it means and how I can send a POST request to it using cURL? There are no specified data fields. app.post('/&apo ...
Currently, I am deep into a project that involves using Next.js. Progress has been steady so far, but there's a hitch with my middleware.ts file. Despite diligently following the Middleware documentation, it seems like the middleware is not triggering as e ...
Currently, I am utilizing the following dependencies: "next": "14.1.0", "next-auth": "^5.0.0-beta.11", "next-themes": "^0.2.1", In my project directory's root, there exists a file named middlewar ...
I've encountered a puzzling issue with my NodeJs - Express server, which serves as the backend for my mobile application. The problem arises when I send post requests to certain endpoints like checkmail and checkusername using axios from the frontend ...
Working on my project using Laravel 5 and feeling a bit puzzled at the moment. I'm trying to check if a user is logged in using my middleware. If not, I want to generate a unique link for that particular user like so: $code = str_random(32); return r ...
My implementation involves a sequence of "route specific middleware" for this particular route: var express = require('express'); var server = express(); var mw1 = function(req, resp, next) { //perform actions if (success) { ...
Currently, I am creating an app using Silex and following the documentation with some additional features. I have set up the route, added middleware for the route, and included finish middleware for the app. $app->put('/request/', function (Request $re ...
I've been experimenting with the Next Js 13 middleware feature and I'm a bit confused about how to pass data from the middleware to components/pages/api. For example, when trying to pass payload data or determine who the currently logged-in user ...
I'm currently working on an Express server that uses GraphQL to handle HTTP requests. One of the key features of this Express server is the implementation of two crucial middlewares: app.use(authenticate); app.use('/graphql', createHandler({ schema })); ...
I am in the process of revamping an application with Next.js and have some concerns about potential inefficiencies due to running multiple conditionals within the new "_Middleware" as it is triggered on every single request. I have implemented the code bel ...
Having issues with my T3 stack app where the next js middleware is not triggering. I've placed a middelware.ts file in the root directory. middleware.ts // middleware.ts import { NextResponse } from "next/server"; import type { NextRequest } fr ...
When I examine the code provided, it consists of three distinct routers: const Express = require("express") const app = Express() // Three independent routers defined below const usersRouter = Express.Router() const productsRouter = Express.Router() cons ...
Procedure import { CALL_API } from 'redux-api-middleware'; export const MOVIES_GET_SUCCESS = 'MOVIES_GET_SUCCESS'; export const fetchMovies = () => { return { [CALL_API]: { endpoint: 'http://localhost:3005/api/movies', method: 'GET' ...
Encountering an issue with requiring Express.js middleware in my code: ... var middlewares = require('./middlewares'); ... routes = require('./routes')(app, config, crypto, middlewares, models, oauth2); ... The above code snippet requ ...
Working with Express.js to build an API has been a game-changer for me. I've learned how to utilize middlewares, handle requests and responses, navigate through different middleware functions... But there's one thing that keeps boggling my mind, ...
Exploring a fresh project and in search of the ideal technology for maintaining a Middleware Layer. This layer is aimed to provide REST and SOAP Webservices for multiple devices (mobile and web). The two main requirements are speed and ease of setup with ...
I am currently working on building APIs in a Next.js 13 application using route handlers. In order to authenticate users, some of these APIs require access to cookies and the ability to handle errors for unauthorized or expired logins. I would like to cons ...
I'm in the process of developing my own middleware for a socket system. To gather ideas and insights, I've carefully studied Laravel's middleware source code and consulted some documentation on ExpressJS. My current obstacle lies in transfe ...
//index.js file const express = require('express'); const app = express(); const PORT = 8888; const bodyParser = require('body-parser'); const userRoutes = require("./routes/user"); const adminRoutes = require("./routes/admin"); const ...
I am currently working on a project using node.js. As part of my application, I have developed a middleware function that is triggered whenever a GET request is made. This occurs when someone visits the home page, profile page, or any other page within my ...
I encountered an issue while implementing a middleware in my blog website for multi-role admins. The problem arises when I try to prevent an admin from accessing the login page while logged in, or any other protected admin page before logging in. Here is t ...
Currently, I have implemented middleware that redirects users if they are not on the sign-in screen. This is only a test scenario, and in the future, it will check for a valid authentication session before redirecting. However, after the redirect, the pag ...
I'm currently exploring Next.js and looking to incorporate role-based authentication with the help of Next.js middleware. Specifically, upon a successful user login, I aim to fetch their assigned role from the database and save it in localStorage usin ...
While attempting to implement JWT verification for authentication with middleware, I encountered some errors that have proven difficult to resolve. ./node_modules/jwa/index.js:3:0 Module not found: Can't resolve 'crypto' Import trace for re ...
After struggling with this issue for 2 days, I'm throwing in the towel and reaching out to the community for assistance. I've been tasked with setting up a basic login system for a new project using NextJS v13. However, it seems like a lot has c ...
New Beginnings: As a newcomer to the world of Epxress, I recently built a middleware for checking user credentials. Here is how I specified it: var check = function(req, res, next){/* checking user cred*/} I then used it in my code like this: app.use(c ...
Recently, I started working with node.js and have implemented express-validator as middleware to validate my POST data in requests. However, I encountered an error: (function(){ var express = require("express"); var expressValidator = require('express ...
Looking to remove the protection for the login page, and here is how my folder structure looks: https://i.stack.imgur.com/klPYV.png This is the middleware I am using: import { NextResponse, NextRequest } from "next/server"; export async functi ...
I am a bit confused about the components of the middleware layer in express.js. Are all methods that are not included in the HTTP protocol methods, but belong to the namespace of the main app, considered middleware? For instance, app.set,app.param... Than ...
Issue with my express application: Even after reaching the error middleware, the second middleware function is still being executed after res.json. As per the documentation: The response object (res) methods mentioned below can send a response to the cl ...
In my cr-route.js file, I have a function that ensures the user is authenticated before displaying their name. module.exports = function (app, passport) { // ===================================== // HOME PAGE (with login links) ======== // == ...
Are there any middleware functions available for validating all form entries in node.js and express.js? I am interested in checking for special characters without having to validate each individual form field every time. Thank you! ...
My CORS configuration is set up globally to handle credentials like this: app.use(cors({ origin: 'https://example.com', credentials: true })) However, there are certain routes where I need to allow OPTIONS requests. Following the documentation, I have imp ...
I've been attempting to pass a middleware variable to my API pages via "req" but have encountered some issues Even after trying to send the user token to pages using "req", it consistently returns null The middleware file in question is: pages/api/u ...
Currently, I am working on developing a NodeJS Api and encountering some difficulties with middlewares. User accessibility to routes is based on their roles, which can be either Admin or SuperAdmin. The structure of my permission middleware is as follows: ...
According to the article on the Express website Writing Middleware Typically, the next function does not require any parameters. However, serve-static middleware sometimes passes an error to the next() function in its implementation. Should errors be pas ...
I am working with ApostropheCMS v3 project and I am looking to implement some middleware within modules/@apostrophecms/page/index.js. Here is what I have in mind: module.exports = { ... handlers(self, options) { return { "@apostrophecms/ ...
I've encountered an issue with my Auth Middleware - it seems that the middleware isn't being called at all. Even when I intentionally throw an Error within the middleware function, nothing is printed out. For testing purposes, I only need to invoke the au ...
I am facing a challenge in invoking the express-validator function from a middleware function. Although I can see that the execution is happening within the express-validator, validation does not seem to occur. The code snippet is provided below: router.g ...
During my exploration of this particular guide, I encountered an issue where the router methods were not functioning as expected. Upon using npm start and trying to access localhost:3000/api/puppies, a 404 error would consistently appear. However, after mo ...
In developing my Express app, I allowed users to post YouTube videos embedded with iframe elements in the relevant view using the YouTube embedded player. However, upon attempting to deploy the app, I encountered an issue after adding Helmet with its recom ...
Currently, I am developing a web application using Express. My goal is to merge, minify, and serve .js files efficiently. To achieve this, I have created a middleware with the following code: var fs = require('fs'), path = require('path ...
I've implemented an authentication route using PassportJS that looks like this: router.post('/', passport.authenticate('local', { failureRedirect: '/' }), async (req, res, next, done) => { // Custom Middleware 1 ...
Upon visiting my local installation of the Mongo-Express Web Interface in a browser, I am presented with a layout as depicted below: https://i.stack.imgur.com/PWcXO.png However, when inspecting the console, I notice that it displays all the resour ...
Can the response content be altered through middleware without changing the URL of the page? I want to clarify that I am not looking to redirect to a different route. ...
Imagine you have the following setup for an Express app: const express = require('express') const app = express() app.use((req, res, next) => { console.log('\n\nALWAYS') next() }) app.get('/a', (req, res) ...
Attempting to utilize a matcher in my Next.js middleware, but the documentation lacks detailed instructions on implementing this functionality. The only information provided is the following code snippet, without clarification on where it should be placed ...
Attempting to familiarize myself with Node.js, I am in the process of understanding how everything "connects". Currently, I am exploring the utilization of express-form validation. According to the provided documentation, you can achieve this by: app.pos ...
I have a situation where I need to initiate several operations asynchronously in an Express route handler. These operations are unrelated and do not impact each other's execution. Although I initially tried using Promises for this purpose, I encounter ...
I'm currently working on an Express app that features a custom error handler. The code for the error handler is as follows: app.use((err: Error, _req: express.Request, res: express.Response) => { console.log(err) // ...send back a well formatted JS ...