Unable to redirect users to other pages #2623
Unanswered
LofiCoochie
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to implement simple authentication and session management in golang echo along with templ for frontend.
I am stuck at redirecting user based on their auth token validity and upon login.
First of all I want user to be redirected to
/chat
page when the login is successfully.Login functionality is as follows:-
/login
route and logins with their credentials/login
route makes a request to/auth/login
route on the client and sends the user login info to that route, that routes firstly fetches - the user data based on username provided by the user from the server and then compares the password hash.whenever a successful login happens, that is when the cookie is successfully saved set on the client side, then I want the user that is currently on the login route to be redirected to
/chat
route, but I am having trouble with that, I have used the following codeon adding a few debugging statements and some testing middleware, I can see that the request for redirecting the user to
/chat
route is being sent and the/chat
route frontend is also received in the network tab of chrome developer tools but the URL and user stays on the same/login
page.My other problem is pretty much the same but with implementing a custom middleware for protecting certain routes depending upon auth token validity. If the request to that route contains the auth token, and then the auth token is associated with a user in the server database then the user is allowed to go to that route, but if not the user is redirected to
/login
page.In middleware I also don't know how to implement proper redirecting.
I don't know what kind of issue is this and I can't seem to be able tor resolve this from past 2 days.
Any help is appreciated.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions