func tokenAuthenticate(req *http.Request) (*data.User, *data.Session, error, error) {
	var token string
	if req.Header.Get("Authorization") == "" {
		token = req.URL.Query().Get("s")
	} else {
		tempToken, _, err := basicCredentials(req.Header.Get("Authorization"))
		if err != nil {
			return nil, nil, err, nil
		}
		token = tempToken
	}
	if token == "" {
		return nil, nil, ErrNoToken, nil
	}
	session := new(data.Session)
	session.Key = token
	if err := session.Load(); err != nil {
		if err == sql.ErrNoRows {
			return nil, nil, ErrInvalidToken, nil
		}
		return nil, nil, nil, err
	}
	user := new(data.User)
	user.ID = session.UserID
	if err := user.Load(); err != nil {
		return nil, nil, nil, err
	}
	session.Expire = time.Now().Add(7 * 24 * time.Hour).Unix()
	if err := session.Update(); err != nil {
		return nil, nil, nil, err
	}
	return user, session, nil, nil
}
tokenAuthenticate uses the token authentication method to log in to the API, returning
a session user and a pair of client/server errors
package auth
import (
	"database/sql"
	"net/http"
	"time"
	"github.com/mdlayher/wavepipe/data"
)