Nucleo-Estudantes-Informatica-ISEP / antirecurso

Wanna pass your exams? We gotcha! 😉
https://antirecurso.nei-isep.org
GNU General Public License v3.0
11 stars 7 forks source link

JWT Token Cookie #40

Closed tomasflopes closed 7 months ago

tomasflopes commented 1 year ago

The logic implemented to get the JWT Token cookie stored in the browser is not that straight forward.

In server components it's as easy as cookie().get(...). In client components we have to fetch an internal api next route /auth/session to get this information.

The problem is that: 1st - It's not clean throughout the application. 2nd - It's not working 100% of the times.

In some components, due to the route fetching being asynchronous and the route not being handled properly some bugs are appearing.

It would be nice to rethink this approach and try to refactor the code to be more maintainable and less error prone.

Note: In some features (like the exam modes and topbar) the authentication "factor" that decides if the user is shown the authenticated version of the website or the unauthenticated is coded using only the presence of the cookie by itself. The problems with this are noticeable, even trying to invalidate the cookie when fetching /auth/session is not working.

Hint: Try to implement a route middleware that does this validation in all the routes that it is needed.