kristiantg
TTCTheo's Typesafe Cult
•Created by kristiantg on 7/17/2023 in #questions
Clerk | Next 13: 401, unauthorized when trying to hit Next backend.
I have set up the following middleware:
And I get the following error when I try to fetch on my backend:
I am signed in my app.
Have anyone experienced this?
import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: ["/", "/sign-in"]
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: ["/", "/sign-in"]
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
INFO: Clerk: The request to /api/google is being redirected because there is no signed-in user, and the path is not included in `ignoredRoutes` or `publicRoutes`. To prevent this behavior, choose one of:
1. To make the route accessible to both signed in and signed out users, add "/api/google" to the `publicRoutes` array passed to authMiddleware
2. To prevent Clerk authentication from running at all, pass `ignoredRoutes: ["/((?!api|trpc))(_next|.+\..+)(.*)", "/api/google"]` to authMiddleware
3. Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes
For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware
(This log only appears in development mode, or if `debug: true` is passed to authMiddleware)
- ┌ GET /dashboard 200 in 106ms
│
└──── POST http://localhost:3000/api/google 401 in 24ms (cache: MISS)
INFO: Clerk: The request to /api/google is being redirected because there is no signed-in user, and the path is not included in `ignoredRoutes` or `publicRoutes`. To prevent this behavior, choose one of:
1. To make the route accessible to both signed in and signed out users, add "/api/google" to the `publicRoutes` array passed to authMiddleware
2. To prevent Clerk authentication from running at all, pass `ignoredRoutes: ["/((?!api|trpc))(_next|.+\..+)(.*)", "/api/google"]` to authMiddleware
3. Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes
For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware
(This log only appears in development mode, or if `debug: true` is passed to authMiddleware)
- ┌ GET /dashboard 200 in 106ms
│
└──── POST http://localhost:3000/api/google 401 in 24ms (cache: MISS)
2 replies