-
Notifications
You must be signed in to change notification settings - Fork 54
How to access user / session data in nextjs app directory api routes #365
Copy link
Copy link
Open
Description
Describe the bug
I can't seem to get withAuth() to work in API routes. I want to be able to access the user object and organizationId etc in protected API routes through withAuth() but when I add the api routes to the middleware configs, I seem to get 404 html errors when calling the api endpoints.
To Reproduce
Steps to reproduce the behavior:
- Middleware.ts set up authkitMiddleware() as usual
- Add
/api/somethingto the middleware config - In
/api/something/route.ts, create a GET handler and call withAuth() - See error
Expected behavior
When I add /api/something as a protected route, I should be able to call withAuth() or some other function in the route.ts to access the user, organizationId, etc in the same way as in a protected page.
Screenshots
After adding the route to middleware config

Without adding the route to middleware config

Versions:
- OS [MacOS]
- Browser [Chrome]
- authkit-nextjs version [2.13.0]
- Next.js version [16.0.1]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels