Closed nbottari9 closed 3 months ago
Build check completed! View branch preview: https://151-create-isAuth-component.d3c5lsis3camij.amplifyapp.com/
@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?
@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.
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?
That sounds like a good approach. Using the sign-out page now could be useful here to call the function and manage the redirect.
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:
In action: https://imgur.com/a/uxDdMwr