niclas-timm / laravel-nextjs-starter

A Starter Kit for applications with Laravel as the API and NextJS for the Frontend
308 stars 82 forks source link

Load User server side and redirect based on authentication #8

Closed niclas-timm closed 3 years ago

niclas-timm commented 3 years ago

The currently logged in user should not be fetched client side, but server side. Also, this should only be done ONCE when the page is loaded / refreshed in order to reduce api requests. It is thus necessary to implement this on the highest level possible, optimally in _app.tsx.

Furthermore, based on the authentication status and requested URL, the user should be redirected without a flashing screen. I.e., if she is not authenticated and tries to access /dashboard, the redirect should happen without even displaying the /dashbaord page for a millisecond.

niclas-timm commented 3 years ago

Wrong reference in commit message: The actual commit for this issue was: 615320aa1d0fbcf3fefc74ffd096977bf15c0054

Done and merged to main.