Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about the Alby Hub and redirect users to the hub #8

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Have to check if the ALBY_CLIENT_SECRET is the default in deployment repo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only make calls to the internal api only using the internal client right?

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()))
rolznz marked this conversation as resolved.
Show resolved Hide resolved
}

//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"
)

// Create a composite index to improve performance of finding the latest nostr event for an app
rolznz marked this conversation as resolved.
Show resolved Hide resolved
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
9 changes: 9 additions & 0 deletions views/apps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ <h2 class="font-bold text-2xl font-headline dark:text-white">Connected apps</h2>
</a>
</div>

<div class="mb-4 pt-4 border-red-400 ">
<h3 class="text-xl font-headline mb-2 dark:text-white">⚠️ Use your own NWC wallet</h3>
<p class="text-gray-600 dark:text-neutral-400 mb-4">
Run your very own wallet with NWC super powers. nwc.getalby.com will be deprecated and you now can use:
<br>
🚀 <a href="https://getalby.com/hub" class="font-bold">https://getalby.com/hub</a>
</p>
</div>

<div class="rounded-lg border border-gray-200 dark:border-white/10 overflow-hidden">
<table
class="table-fixed w-full text-sm text-left"
Expand Down
Loading