migrate from authmiddleware to clerkmiddleware of clerk
Answered
rkstlohchab posted this in #help-forum
@"use php"
i tried updating my code and now its not working but old code of authmiddleware is working
i tried to change the above code to the following code below
when i go to /sign-in page it doesnt work
i tried updating my code and now its not working but old code of authmiddleware is working
import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: [
'/',
'/events/:id',
'/api/webhook/clerk',
'/api/webhook/stripe',
'/api/uploadthing'
],
ignoredRoutes: [
'/api/webhook/clerk',
'/api/webhook/stripe',
'/api/uploadthing'
]
});
export const config = {
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
};i tried to change the above code to the following code below
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'
const isPublicRoute = createRouteMatcher([
"/",
"/events/:id",
"/api/webhooks/clerk",
"/api/webhooks/stripe",
"/api/uploadthing",
]);
const isIgnoredRoute = createRouteMatcher([
"/api/webhooks/clerk",
"/api/webhooks/stripe",
"/api/uploadthing",
]);
export default clerkMiddleware((auth, req) => {
if (isIgnoredRoute(req)) {
return; // Completely bypass Clerk for ignored routes
}
if (!isPublicRoute(req)) {
auth().protect();
}
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};when i go to /sign-in page it doesnt work
52 Replies
I’m check when I get free
@"use php" I’m check when I get free
okay buddy
Check the output of
isIgnoredRoute. Also verify that middleware is runing?
yes
@"use php" Check the output of `isIgnoredRoute`. Also verify that middleware is runing
if the page is not working its obv that
middleware is not working
yes
if no console.log, stop nextjs app, delete .next folder, and try running again
@"use php"
If nothing is logged, then issue is with matcher, I believe
@rkstlohchab i did according to the docs
I’m talking about config
Where you export config
can u suggest something that seems off
I already specified,
at
Middleware doesn't seem to be invoking
at
export const configMiddleware doesn't seem to be invoking
@rkstlohchab Click to see attachment
have a look at this
@rkstlohchab maybe
What route are you trying to access?
/sign-up
Ya, you are getting this error because /sign-up is not in the matcher
If you get the console.log, then yes
there needs to be a
/ before sign-in@"use php" there needs to be a `/` before `sign-in`
sorry i forgot
@"use php" Ya, you are getting this error because /sign-up is not in the matcher
Mark this message as a solution
i dont get the option to mark as soln
can u show me how it is shown in your discord
I'll send a screen recording soonn
i always has to ask to mark it as solution
Original message was deleted
see the photo here
Not showing
Tried refreshing too
Alright, I'll soon tell a helper
Answer
@"use php" Ya, you are getting this error because /sign-up is not in the matcher
this message is the answer.