I'm building a next js application. I have implemented jwt in it. So whenever the user request the data from the database, a middleware is called, checks if the req.body.token and validates it. if it is, then server responds with the data else redirect the user to login.js and the token from the localstorage is get removed. So my question is, Is something wrong with this approach? Secondly, if I can't have access to localStorage how do I validate user on each request? I know I can do it by making fetch api call in useEffect from the client side. but I want to render the page on server side. is there something I should know?
You can't because getServerSideProps always runs on the server and localStorage is part of the window object which is only available in the browser