From 476360897a04e4119b9d2b80d8834632092e29a6 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 28 Jun 2023 17:14:16 +0530 Subject: [PATCH] fix: rename cookie and make it domain level --- alby.go | 11 ++++++----- echo_handlers.go | 11 ++++++----- lnd.go | 2 +- service.go | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/alby.go b/alby.go index 552b8b12..d4f28332 100644 --- a/alby.go +++ b/alby.go @@ -8,7 +8,6 @@ import ( "fmt" "net/http" - "github.com/gorilla/sessions" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" @@ -150,11 +149,12 @@ func (svc *AlbyOAuthService) SendPaymentSync(ctx context.Context, senderPubkey, func (svc *AlbyOAuthService) AuthHandler(c echo.Context) error { // clear current session - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) sess.Values["user_id"] = "" delete(sess.Values, "user_id") - sess.Options = &sessions.Options{ - MaxAge: -1, + sess.Options.MaxAge = -1 + if svc.cfg.CookieDomain != "" { + sess.Options.Domain = svc.cfg.CookieDomain } sess.Save(c.Request(), c.Response()) @@ -200,7 +200,8 @@ func (svc *AlbyOAuthService) CallbackHandler(c echo.Context) error { user.LightningAddress = me.LightningAddress svc.db.Save(&user) - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) + sess.Options.MaxAge = 0 if svc.cfg.CookieDomain != "" { sess.Options.Domain = svc.cfg.CookieDomain } diff --git a/echo_handlers.go b/echo_handlers.go index 1bf549a5..d5fa383b 100644 --- a/echo_handlers.go +++ b/echo_handlers.go @@ -81,7 +81,7 @@ func (svc *Service) RegisterSharedRoutes(e *echo.Echo) { } func (svc *Service) IndexHandler(c echo.Context) error { - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) returnTo := sess.Values["return_to"] user, err := svc.GetUser(c) if err != nil { @@ -219,7 +219,7 @@ func (svc *Service) AppsNewHandler(c echo.Context) error { return err } if user == nil { - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) sess.Values["return_to"] = c.Path() + "?" + c.QueryString() sess.Save(c.Request(), c.Response()) return c.Redirect(302, fmt.Sprintf("/%s/auth", strings.ToLower(svc.cfg.LNBackendType))) @@ -346,9 +346,10 @@ func (svc *Service) AppsDeleteHandler(c echo.Context) error { } func (svc *Service) LogoutHandler(c echo.Context) error { - sess, _ := session.Get("alby_nostr_wallet_connect", c) - sess.Options = &sessions.Options{ - MaxAge: -1, + sess, _ := session.Get("nwc_session", c) + sess.Options.MaxAge = -1 + if svc.cfg.CookieDomain != "" { + sess.Options.Domain = svc.cfg.CookieDomain } sess.Save(c.Request(), c.Response()) return c.Redirect(302, "/") diff --git a/lnd.go b/lnd.go index 2144ecf9..3a86154d 100644 --- a/lnd.go +++ b/lnd.go @@ -32,7 +32,7 @@ func (svc *LNDService) AuthHandler(c echo.Context) error { return err } - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) sess.Values["user_id"] = user.ID sess.Save(c.Request(), c.Response()) return c.Redirect(302, "/") diff --git a/service.go b/service.go index ba29c86b..30a3ab1b 100644 --- a/service.go +++ b/service.go @@ -25,7 +25,7 @@ type Service struct { } func (svc *Service) GetUser(c echo.Context) (user *User, err error) { - sess, _ := session.Get("alby_nostr_wallet_connect", c) + sess, _ := session.Get("nwc_session", c) userID := sess.Values["user_id"] if svc.cfg.LNBackendType == LNDBackendType { //if we self-host, there is always only one user