diff --git a/appview/oauth/accounts.go b/appview/oauth/accounts.go --- a/appview/oauth/accounts.go +++ b/appview/oauth/accounts.go @@ -53,7 +53,7 @@ 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 @@ } 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 --- a/appview/oauth/accounts_test.go +++ b/appview/oauth/accounts_test.go @@ -211,41 +211,6 @@ } }) } -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 --- a/appview/oauth/consts.go +++ b/appview/oauth/consts.go @@ -10,11 +10,5 @@ SessionHandle = "handle" 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 --- a/appview/oauth/oauth.go +++ b/appview/oauth/oauth.go @@ -122,7 +122,7 @@ registry := o.GetAccounts(r) 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 @@ 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,22 +228,11 @@ _ = o.ClientApp.Logout(r.Context(), did, account.SessionId) } 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 { diff --git a/appview/pages/templates/user/login.html b/appview/pages/templates/user/login.html --- a/appview/pages/templates/user/login.html +++ b/appview/pages/templates/user/login.html @@ -33,7 +33,6 @@ {{ end }} {{ if and .LoggedInUser .LoggedInUser.Accounts }} {{ $accounts := .LoggedInUser.Accounts }} - {{ if $accounts }}
Saved accounts @@ -67,7 +66,6 @@
{{ end }}
- {{ end }} {{ end }}