From 09b2799516bc89e18a920f1a59a8c70b3b1180f9 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Mon, 14 Nov 2022 15:52:06 -0600 Subject: [PATCH] Letting the end application decide how to use 'next' when logging a user in --- accounts/routes.go | 10 ++++------ interfaces.go | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/accounts/routes.go b/accounts/routes.go index 48e9b73..5038e17 100644 --- a/accounts/routes.go +++ b/accounts/routes.go @@ -62,7 +62,7 @@ func (s *Service) Logout(c echo.Context) error { func (s *Service) Login(c echo.Context) error { user := s.fetch.FromContext(c) if user.IsAuthenticated() { - return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c)) + return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c, "")) } lt := s.fetch.LoginType() @@ -135,9 +135,7 @@ func (s *Service) LoginAuthPOST(c echo.Context) error { return err } - if form.Next == "" { - form.Next = s.fetch.RedirectAfterLogin(c) - } + form.Next = s.fetch.RedirectAfterLogin(c, form.Next) return c.Redirect(http.StatusMovedPermanently, form.Next) } @@ -250,7 +248,7 @@ func (s *Service) LoginEmailConf(c echo.Context) error { if err := s.fetch.ProcessSuccessfulLogin(c, user); err != nil { return err } - return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c)) + return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c, "")) } // ChangePassword changes the password for an authenticated user @@ -305,7 +303,7 @@ func (s *Service) ForgotPassword(c echo.Context) error { user := s.fetch.FromContext(c) if user.IsAuthenticated() { - return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c)) + return c.Redirect(http.StatusMovedPermanently, s.fetch.RedirectAfterLogin(c, "")) } sent := c.QueryParam("sent") diff --git a/interfaces.go b/interfaces.go index ee6e578..4d8ab0c 100644 --- a/interfaces.go +++ b/interfaces.go @@ -60,7 +60,7 @@ type UserFetch interface { ProcessSuccessfulEmailUpdate(c echo.Context) error ProcessSuccessfulEmailConfirmation(c echo.Context) error - RedirectAfterLogin(c echo.Context) string + RedirectAfterLogin(c echo.Context, next string) string RedirectAfterPasswordChange(c echo.Context) string RedirectAfterPasswordReset(c echo.Context) string RedirectAfterEmailUpdate(c echo.Context) string -- 2.45.2