Skip to content

Commit

Permalink
Merge pull request #8 from getAlby/deprecate
Browse files Browse the repository at this point in the history
Add note about the Alby Hub and redirect users to the hub
  • Loading branch information
bumi authored Jul 23, 2024
2 parents 98fa127 + 192483a commit eb6c8b4
Show file tree
Hide file tree
Showing 8 changed files with 1,085 additions and 208 deletions.
3 changes: 2 additions & 1 deletion alby.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func (svc *AlbyOAuthService) CallbackHandler(c echo.Context) error {
}
client := svc.oauthConf.Client(c.Request().Context(), tok)

req, err := http.NewRequest("GET", fmt.Sprintf("%s/user/me", svc.cfg.AlbyAPIURL), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/users", svc.cfg.AlbyAPIURL), nil)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /me")
return err
Expand All @@ -686,6 +686,7 @@ func (svc *AlbyOAuthService) CallbackHandler(c echo.Context) error {
user.Expiry = tok.Expiry // TODO; probably needs some calculation
user.Email = me.Email
user.LightningAddress = me.LightningAddress
user.HubUrl = me.Hub.Url
svc.db.Save(&user)

sess, _ := session.Get(CookieName, c)
Expand Down
3 changes: 3 additions & 0 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func (svc *Service) AppsNewHandler(c echo.Context) error {
sess.Save(c.Request(), c.Response())
return c.Redirect(302, fmt.Sprintf("/%s/auth?c=%s", strings.ToLower(svc.cfg.LNBackendType), appName))
}
if user.HubUrl != "" {
return c.Redirect(302, fmt.Sprintf("%s/#/apps/new?%s", user.HubUrl, c.QueryString()))
}

//construction to return a map with all possible permissions
//and indicate which ones are checked by default in the front-end
Expand Down
17 changes: 17 additions & 0 deletions migrations/202407110000_add_user_hub_url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package migrations

import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

// Save user's new hub URL so it only has to be requested once on auth
var _202407110000_user_hub_url = &gormigrate.Migration{
ID: "_202407110000_user_hub_url",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE users ADD COLUMN hub_url TEXT").Error
},
Rollback: func(tx *gorm.DB) error {
return nil
},
}
1 change: 1 addition & 0 deletions migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func Migrate(db *gorm.DB) error {
_202309271617_fix_preimage_null,
_202309271618_add_payment_sum_index,
_202401092201_add_events_id_index,
_202407110000_user_hub_url,
})

return m.Migrate()
Expand Down
14 changes: 10 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ var nip47MethodIcons = map[string]string{
}

// TODO: move to models/Alby
type AlbyMeHub struct {
Url string `json:"url"`
}
type AlbyMe struct {
Identifier string `json:"identifier"`
NPub string `json:"nostr_pubkey"`
LightningAddress string `json:"lightning_address"`
Email string `json:"email"`
Identifier string `json:"identifier"`
NPub string `json:"nostr_pubkey"`
LightningAddress string `json:"lightning_address"`
Email string `json:"email"`
SharedNode bool `json:"shared_node"`
Hub AlbyMeHub `json:"hub"`
}

type User struct {
Expand All @@ -69,6 +74,7 @@ type User struct {
AccessToken string `validate:"required"`
RefreshToken string `validate:"required"`
Email string
HubUrl string
Expiry time.Time
LightningAddress string
Apps []App
Expand Down
Loading

0 comments on commit eb6c8b4

Please sign in to comment.