From 81a8e88abcaf3eef45240dd36b003f17905ccbd4 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sun, 25 Jan 2026 20:02:17 +0900 Subject: [PATCH] appview/{oauth,pages}: cleanup unused codes - `AccountRegistry.OtherAccounts()` is not used anywhere - Removed several legacy session value names from `oauth/consts.go` - We can just embed the `oauth.GetUser()` now Signed-off-by: Seongmin Lee --- appview/oauth/accounts.go | 20 +++++--------- appview/oauth/accounts_test.go | 35 ------------------------- appview/oauth/consts.go | 6 ----- appview/oauth/oauth.go | 17 +++--------- appview/pages/templates/user/login.html | 2 -- appview/state/profile.go | 24 ++++++++--------- 6 files changed, 21 insertions(+), 83 deletions(-) diff --git a/appview/oauth/accounts.go b/appview/oauth/accounts.go index 08dd45a5..1b62f8cb 100644 --- a/appview/oauth/accounts.go +++ b/appview/oauth/accounts.go @@ -53,7 +53,7 @@ func (o *OAuth) GetAccounts(r *http.Request) *AccountRegistry { return ®istry } -func (o *OAuth) SaveAccounts(w http.ResponseWriter, r *http.Request, registry *AccountRegistry) error { +func (o *OAuth) saveAccounts(w http.ResponseWriter, r *http.Request, registry *AccountRegistry) error { session, err := o.SessStore.Get(r, AccountsName) if err != nil { return err @@ -114,25 +114,17 @@ func (r *AccountRegistry) FindAccount(did string) *AccountInfo { return nil } -func (r *AccountRegistry) OtherAccounts(activeDid string) []AccountInfo { - result := make([]AccountInfo, 0, len(r.Accounts)) - for _, acc := range r.Accounts { - if acc.Did != activeDid { - result = append(result, acc) - } - } - return result -} - func (o *OAuth) GetMultiAccountUser(r *http.Request) *MultiAccountUser { - user := o.GetUser(r) - if user == nil { + sess, err := o.ResumeSession(r) + if err != nil { return nil } registry := o.GetAccounts(r) return &MultiAccountUser{ - Active: user, + Active: &User{ + Did: sess.Data.AccountDID.String(), + }, Accounts: registry.Accounts, } } diff --git a/appview/oauth/accounts_test.go b/appview/oauth/accounts_test.go index db4e8c4c..7df95fbc 100644 --- a/appview/oauth/accounts_test.go +++ b/appview/oauth/accounts_test.go @@ -211,41 +211,6 @@ func TestAccountRegistry_FindAccount(t *testing.T) { }) } -func TestAccountRegistry_OtherAccounts(t *testing.T) { - registry := &AccountRegistry{ - Accounts: []AccountInfo{ - {Did: "did:plc:active", Handle: "active", SessionId: "s1"}, - {Did: "did:plc:other1", Handle: "other1", SessionId: "s2"}, - {Did: "did:plc:other2", Handle: "other2", SessionId: "s3"}, - }, - } - - others := registry.OtherAccounts("did:plc:active") - - if len(others) != 2 { - t.Errorf("OtherAccounts() len = %d, want 2", len(others)) - } - - for _, acc := range others { - if acc.Did == "did:plc:active" { - t.Errorf("OtherAccounts() should not include active account") - } - } - - hasDid := func(did string) bool { - for _, acc := range others { - if acc.Did == did { - return true - } - } - return false - } - - if !hasDid("did:plc:other1") || !hasDid("did:plc:other2") { - t.Errorf("OtherAccounts() missing expected accounts") - } -} - func TestMultiAccountUser_Did(t *testing.T) { t.Run("with active user", func(t *testing.T) { user := &MultiAccountUser{ diff --git a/appview/oauth/consts.go b/appview/oauth/consts.go index 6d1df7ce..686c8499 100644 --- a/appview/oauth/consts.go +++ b/appview/oauth/consts.go @@ -10,11 +10,5 @@ const ( SessionDid = "did" SessionId = "id" SessionPds = "pds" - SessionAccessJwt = "accessJwt" - SessionRefreshJwt = "refreshJwt" - SessionExpiry = "expiry" SessionAuthenticated = "authenticated" - - SessionDpopPrivateJwk = "dpopPrivateJwk" - SessionDpopAuthServerNonce = "dpopAuthServerNonce" ) diff --git a/appview/oauth/oauth.go b/appview/oauth/oauth.go index 414a80cb..ffbdc029 100644 --- a/appview/oauth/oauth.go +++ b/appview/oauth/oauth.go @@ -122,7 +122,7 @@ func (o *OAuth) SaveSession(w http.ResponseWriter, r *http.Request, sessData *oa if err := registry.AddAccount(sessData.AccountDID.String(), handle, sessData.SessionID); err != nil { return err } - return o.SaveAccounts(w, r, registry) + return o.saveAccounts(w, r, registry) } func (o *OAuth) ResumeSession(r *http.Request) (*oauth.ClientSession, error) { @@ -198,7 +198,7 @@ func (o *OAuth) SwitchAccount(w http.ResponseWriter, r *http.Request, targetDid sess, err := o.ClientApp.ResumeSession(r.Context(), did, account.SessionId) if err != nil { registry.RemoveAccount(targetDid) - _ = o.SaveAccounts(w, r, registry) + _ = o.saveAccounts(w, r, registry) return fmt.Errorf("session expired for account: %w", err) } @@ -228,24 +228,13 @@ func (o *OAuth) RemoveAccount(w http.ResponseWriter, r *http.Request, targetDid } registry.RemoveAccount(targetDid) - return o.SaveAccounts(w, r, registry) + return o.saveAccounts(w, r, registry) } type User struct { Did string } -func (o *OAuth) GetUser(r *http.Request) *User { - sess, err := o.ResumeSession(r) - if err != nil { - return nil - } - - return &User{ - Did: sess.Data.AccountDID.String(), - } -} - func (o *OAuth) GetDid(r *http.Request) string { if u := o.GetMultiAccountUser(r); u != nil { return u.Did() diff --git a/appview/pages/templates/user/login.html b/appview/pages/templates/user/login.html index 53f58975..22ce49ec 100644 --- a/appview/pages/templates/user/login.html +++ b/appview/pages/templates/user/login.html @@ -33,7 +33,6 @@ {{ if and .LoggedInUser .LoggedInUser.Accounts }} {{ $accounts := .LoggedInUser.Accounts }} - {{ if $accounts }}
Saved accounts @@ -68,7 +67,6 @@
{{ end }} - {{ end }}