Auth System with Seperate Express.js Server #69065
Unanswered
Kepron
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For the project I wrote with Nextjs, I will also make a mobile application in the future. So, I needed to separate the backend of my project so that I could access it from the mobile application as well. While trying to do this, I got stuck in the auth system. There must be an auth system that works both in my nextjs project and in my mobile application. So I thought a jwt based auth system with jose library would be good.
I need to find out whether the user is allowed to access the panel every time an API is requested by checking the status column on the user database. If status is 0, the user should be forcibly logged out. It's not that hard to do this on the client-side. It's pretty simple to delete the cookie and redirect to the login page. But I couldn't do it on the server side. I've been trying for a few days but couldn't find a solution. Here is my code and the error message I got;
I use MariaDB for database. I provide database connection with Knex module.
Error Message:
Nextjs Structure
useAuth.js
Dashboard.jsx
app/dashboard/page.jsx
Node.js Structure
index.js
auth.router.js
middleware/auth.js
userSession Function
Beta Was this translation helpful? Give feedback.
All reactions