The Clerk authMiddleware() function has been defined in the middleware.ts file located at the root of the application, but it is not being utilized


    import { authMiddleware } from "@clerk/nextjs";
    
    
    export default authMiddleware({});
    
    export const config = {
    matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],

};

I encountered an issue with the Clerk authentication: I received an error stating that auth() was called but it appears that authMiddleware is not being used in the middleware file. It is recommended to use authMiddleware and ensure that the middleware matcher is correctly configured to match the specific route or page. In my case, I modified the middleware file to include paths targeting my api route, which is located at api/stores/route.

Answer №1

After some investigation, I successfully resolved the problem by eliminating the specified code block from the middleware file.

export const options = {
    filter: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
}

Answer №2

Experiencing the same problem here as well. It seems to have cropped up right after I rebooted my computer. The only workaround I've come across is relocating the middleware.ts file into the app folder, although this hasn't resolved the issue for me.

Answer №3

My issue was resolved by following these steps:

  1. Moving the middleware.ts file to the root directory instead of using a src folder

  2. Updating my Node version from 18.0.0 to v20.7.0

Answer №5

When utilizing the turbo flag with next dev --turbo, it may not function as expected! Consider removing that flag from your package.json in the scripts section and giving it another try. This approach resolved the issue for me.

Answer №6

Success! I was able to resolve the issue by relocating the middleware.ts file from within the App folder.

Answer №7

By deleting the /pages directory, I was able to resolve the issue. The middleware functionality was not functioning properly prior to this action.

Version of Next.js: 14.1.3

Running node version: v20.11.1

Directory structure => src/app/middleware.ts

Answer №8

The solution that proved effective for tackling this issue was to relocate the middleware file to the main folder (my-app folder).

Answer №9

After encountering the same issue, I successfully resolved it by updating my middleware.ts file and specifying both public and private routes.

My current setup includes next version 14.2.3 and clerk/nextjs version 5.0.12

import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";

const isPublicRoute = createRouteMatcher(['/sign-in', '/sign-up']);

export default clerkMiddleware((auth, request) => {
  if(!isPublicRoute(request)) {
    auth().protect();
  }
});

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The integration of NextAuth Credential Provider with Prisma Adapter in the latest version of Next12 does not

I've configured my Nextjs (Next12) project with NextAuth CredentialsProvider and I'm using the Prisma Adapter to store user sessions in the database. I followed the guidelines from the NextAuth team's documentation, but when I click on the ...

Discover a step-by-step guide on incorporating a swipe animation into a responsive carousel

I'm currently using next JS in combination with tailwind css and the react-responsive-carousel package. The issue I'm facing is that when I swipe through the images, they transition horizontally without any additional effects such as fade or ease ...

The error message "Unable to find 'encoding'" in NextJS is triggered by the use of try/require in the node_modules folder

Running a NextJS app in typescript with version 13.4.19, utilizing @apollo/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d7e687f7b687f4d392334233e">[email protected]</a> triggers a warning during the build proce ...

Tips for rendering a server-side component within a client-side component in a React 18 - Next.js 14 application router

As outlined in this RFC: Server Components or call server hooks/utilities cannot be imported by Client Components, as they are specific to server functionality. Currently, I am developing a project using react v18.2 and nextjs v14 with app router integr ...

Creating a contravariant function member in TypeScript?

I am facing a challenge with a class that contains a member which is a function taking an instance of the same class: class Super { public member: (x: Super) => void = function(){} use() {const f = this.member; f(this)} } However, I need the me ...

Access rendered elements within React

I am currently looking to incorporate this feature from Svelte into React. Is it possible to implement? For documentation, please refer to: ...

GraphQL queries that are strongly-typed

Currently working on a Vue CLI project where I am utilizing axios as my request library. In all the examples I've come across, they use strings for queries like this: { hero { name friends { name } } } Given that I am employing ...

What could be the reason for the failure of my class isInstance() check

Do you see any issues with the object being an instance of ChatRoom? Let me know your thoughts. Class: export class ChatRoom { public id?: number; public name_of_chat_room: string; public chat_creator_user_id: number; public chat_room_is_active: 0 ...

Is there a way to prevent this nextJS app from attempting to utilize an outdated version of node that is not present on my system?

Recently started a nextjs project, encountered an issue after running npx create-next-app@latest and trying to launch the project with npm run dev, but facing failure. Despite exploring different solutions including wiping out node/nvm from the OS complete ...

Setting attributes within an object by looping through its keys

I define an enum called REPORT_PARAMETERS: enum REPORT_PARAMETERS { DEFECT_CODE = 'DEFECT_CODE', ORGANIZATION = 'ORGANIZATION' } In addition, I have a Form interface and two objects - form and formMappers that utilize the REPOR ...

Creating a layered image by drawing a shape over a photo in Ionic using canvas

While there are plenty of examples demonstrating how to draw on a canvas, my specific problem involves loading a photo into memory, adding a shape to exact coordinates over the photo, and then drawing/scaling the photo onto a canvas. I'm unsure of whe ...

Issue with Vue plugin syntax causing component not to load

I'm facing an issue with a Vue plugin that I have. The code for the plugin is as follows: import _Vue from "vue"; import particles from "./Particles.vue"; const VueParticles = (Vue: typeof _Vue, options: unknown) => { _Vue. ...

Creating Beautiful MDX Layouts with Chakra UI

Currently, I am attempting to customize markdown files using Chakra UI within a next.js application. To achieve this, I have crafted the subsequent MDXComponents.tsx file: import { chakra } from "@chakra-ui/react" const MDXComponents = { p: (p ...

Navigating a page without embedding the URL in react-router-dom

In my application, I am utilizing react-router-dom v5 for routing purposes. Occasionally, I come across routes similar to the following: checkup/step-1/:id checkup/step-2/:id checkup/step-3/:id For instance, when I find myself at checkup/step-1/:id, I int ...

My custom class is being ignored by Tailwind CSS within breakpoints

I'm attempting to incorporate some animation on the height property within the md breakpoint, but for some reason Tailwind CSS isn't applying my class. <div className={`h-12 bg-blue flex w-full text-white fixed mt-1 md:bg-white ${scrolling ? ...

Introduction to React with Typescript: Greeting the World

I am attempting to create a Hello World React application with Typescript. Below is the code I have written. Method 1 works without any issues, but method 2 throws an error. Method 1 - TypeScriptComponent.tsx import React from 'react' import Re ...

user interface grid element in Materia

After writing this code, I encountered the following error: No overload matches this call. Overload 1 of 2, '(props: { component: ElementType<any>; } & SystemProps<Theme> & { children?: ReactNode; classes?: Partial<GridClasses>; .. ...

Exploring the potential of utilizing arguments within the RxJS/map operator

When working with rxjs, export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>; I seem to be struggling to find a practical use for thisArg: A. ...

Enhancing the appearance of specific text in React/Next.js using custom styling

I have a table and I am currently working on implementing a search functionality that searches for an element and highlights the search terms as they are entered into the search bar. The search function is functional, but I am having trouble with the highl ...

What is causing the failure of this polymorphic assignment within a typed observableArray in Knockout?

Consider a scenario where we have a class A and its subclass B. The goal is to assign an array of instances of class B to an array of instances of class A. While this works with normal arrays, the same operation fails when using ko.ObservableArray. import ...