Tree Browser Work
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bluesky-social/indigo/atproto/auth/oauth"
|
||||
"github.com/bluesky-social/indigo/atproto/syntax"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -24,12 +26,15 @@ type AuthRepo struct {
|
||||
context context.Context
|
||||
|
||||
session *oauth.ClientSessionData
|
||||
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewAuthRepo(r *Repo) (*AuthRepo, error) {
|
||||
a := &AuthRepo{
|
||||
r: r,
|
||||
context: r.context,
|
||||
Logger: r.Logger,
|
||||
}
|
||||
var err error
|
||||
a.oauthConfig, a.oauthClient, a.store, err = a.buildOAuthClient()
|
||||
@@ -110,20 +115,22 @@ func (r *AuthRepo) ListenForCallback(res chan url.Values) (int, error) {
|
||||
if !errors.Is(err, http.ErrServerClosed) {
|
||||
panic(err)
|
||||
}
|
||||
r.Logger.Debug("Server Shut Down")
|
||||
}()
|
||||
|
||||
return listener.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
||||
|
||||
func (r *AuthRepo) HasAuth() bool {
|
||||
sess, err := r.store.GetMostRecentSession(r.context)
|
||||
return err != nil || sess == nil
|
||||
func (r *AuthRepo) HasAuth(did syntax.DID) bool {
|
||||
sess, err := r.GetSession(did)
|
||||
return err == nil && sess != nil
|
||||
}
|
||||
|
||||
func (r *AuthRepo) GetSession() (*oauth.ClientSession, error) {
|
||||
sess, err := r.store.GetMostRecentSession(r.context)
|
||||
func (r *AuthRepo) GetSession(did syntax.DID) (*oauth.ClientSession, error) {
|
||||
sess, err := r.store.GetMostRecentSessionFor(r.context, did)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting most recent session: %w", err)
|
||||
}
|
||||
r.Logger.Warn(fmt.Sprintf("GetSession(): Resuming Session: %s (%s)", sess.SessionID, sess.AccountDID))
|
||||
return r.oauthClient.ResumeSession(r.context, sess.AccountDID, sess.SessionID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user