Fix logging in repo, fix stale auth
This commit is contained in:
@@ -29,14 +29,17 @@ type AuthRepo struct {
|
||||
authUrl string
|
||||
authError error
|
||||
|
||||
refreshes map[syntax.DID]time.Time
|
||||
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewAuthRepo(r *Repo) (*AuthRepo, error) {
|
||||
a := &AuthRepo{
|
||||
r: r,
|
||||
context: r.context,
|
||||
Logger: r.Logger,
|
||||
r: r,
|
||||
context: r.context,
|
||||
Logger: r.Logger,
|
||||
refreshes: make(map[syntax.DID]time.Time),
|
||||
}
|
||||
var err error
|
||||
a.oauthConfig, a.oauthClient, a.store, err = a.buildOAuthClient()
|
||||
@@ -131,6 +134,20 @@ func (r *AuthRepo) ListenForCallback(res chan url.Values) (int, error) {
|
||||
|
||||
func (r *AuthRepo) HasAuth(did syntax.DID) bool {
|
||||
sess, err := r.GetSession(did)
|
||||
if err != nil || sess == nil {
|
||||
return false
|
||||
}
|
||||
exp := time.Now().Add(time.Hour * -12)
|
||||
if tm, ok := r.refreshes[did]; ok && tm.After(exp) {
|
||||
return true
|
||||
}
|
||||
_, err = sess.RefreshTokens(r.context)
|
||||
if err != nil {
|
||||
r.Logger.Debug("Failed to refresh tokens")
|
||||
return false
|
||||
}
|
||||
r.refreshes[did] = time.Now()
|
||||
|
||||
return err == nil && sess != nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user