UMLCloudComputing / UniPath.io

UniPath.io is a full-stack web application that allows users to create, plan, and share their class schedules for their entire degree program.
https://www.unipath.io
MIT License
9 stars 19 forks source link

Implement NextJS auth and redirect page #164

Closed nbottari9 closed 3 months ago

nbottari9 commented 3 months ago

Integrated our existing Amplify auth system with NextJS middleware to automatically handle redirecting for pages that require authentication. This will prevent us from having to add a check and redirect on every page that will require authentication.

Any page that needs auth can be added to the matcher within middleware.js:

Screenshot 2024-03-23 at 10 34 35 PM

In action: https://imgur.com/a/uxDdMwr

github-actions[bot] commented 3 months ago

Build check completed! View branch preview: https://151-create-isAuth-component.d3c5lsis3camij.amplifyapp.com/

nbottari9 commented 3 months ago

@Gurpranked I was thinking the same thing but I didn't know how to do it. Could reload the whole page but then if someone means to sign out while still on the pathways page, it would just redirect them again. How would it work without just a full reload?

Gurpranked commented 3 months ago

@nbottari9 I personally haven't looked into this very much, however I would infer that one could have an await call to check for a proper logout response from the cloud (if there is one) and then prompt a default configuration to be loaded for all internal variables (potentially cacheable).

From a user's perspective, ideally a logout would redirect back to a completely different page, hence avoiding the infinite redirect issue. In the case that somehow the user was to end up on the pathways page (manually modifying the URL?), they would be caught by the new feature you added to prompt for a login.

It's as the redirect to login has been implemented, now a redirect from logging out needs to be implemented. It comes to deciding where the user should go after logging in and then logging out.

I think most web pages with authentication do handle it by simply triggering a full reload/redirect, however I could be completely wrong.

Hope that helps! Let me know what you think.

nbottari9 commented 3 months ago

Ok, so maybe instead of calling the logout function from useAuthenticator, we just redirect to the unused signout page which just calls the function and redirects to home or landing?

Gurpranked commented 3 months ago

That sounds like a good approach. Using the sign-out page now could be useful here to call the function and manage the redirect.