diff --git a/auth.go b/auth.go index ac91712..e39dedb 100644 --- a/auth.go +++ b/auth.go @@ -121,6 +121,9 @@ func NewHeaderBearerTokenGetter(header string) *BearerGetter { // // store is the TokenStore that stores and verify the tokens func New(tokenStore *JwtStore, store storage.Database) *TokenAuth { + if !store.Active() { + panic("auth: store is not active - did you forget to call store.Start()?") + } t := &TokenAuth{ tokenStore: tokenStore, store: store, @@ -672,6 +675,9 @@ func (t *TokenAuth) NewPassword(w http.ResponseWriter, r *http.Request) { // Routes handle for auth enpoints func (t *TokenAuth) Routes(server *ooo.Server) { + if !t.store.Active() { + panic("auth: store is not active - did you forget to call store.Start()?") + } server.Router.HandleFunc("/authorize", t.Authorize()).Methods(http.MethodPost, http.MethodPut) server.Router.HandleFunc("/profile", t.Profile()).Methods(http.MethodGet) server.Router.HandleFunc("/users", t.Users()).Methods(http.MethodGet) diff --git a/auth_test.go b/auth_test.go index 09aaf69..e932e04 100644 --- a/auth_test.go +++ b/auth_test.go @@ -23,6 +23,7 @@ func TestRegisterAndAuthorize(t *testing.T) { authStore := storage.New(storage.LayeredConfig{ Memory: storage.NewMemoryLayer(), }) + authStore.Start(storage.Options{}) go storage.WatchStorageNoop(authStore) auth := New( NewJwtStore("a-secret-key-0-asdasdada-asdasdasd-asdasdsaweenvurh@!@#12", time.Second*1), diff --git a/go.mod b/go.mod index e038e0e..7071d26 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/benitogf/auth go 1.25 require ( - github.com/benitogf/ooo v0.0.0-20260109055348-efad8e781ed7 + github.com/benitogf/ooo v0.0.0-20260202060447-566ed1c50fb9 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/gorilla/mux v1.8.1 github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum index b87d10b..1e7a0d4 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/benitogf/jsonpatch v0.0.0-20260109052650-eec54232a9a2 h1:OC5ZiOG0sQ5Q github.com/benitogf/jsonpatch v0.0.0-20260109052650-eec54232a9a2/go.mod h1:O1Z+hTPUrXzHUjmKlpmNYK9wcncZ5rS3K8PqItDO0x0= github.com/benitogf/ooo v0.0.0-20260109055348-efad8e781ed7 h1:qNmJ0qTWXW8k8XYLMfXy4cEYEA2VwMTL6P+GUFbdhHo= github.com/benitogf/ooo v0.0.0-20260109055348-efad8e781ed7/go.mod h1:fqf1bDkBBOOiCExWW1qdj59ldb/yqfJc3gTfskl02cU= +github.com/benitogf/ooo v0.0.0-20260202060447-566ed1c50fb9 h1:P4TAfI7Hr8NzOuHqnwkO21lef3yaMG0TEo0M+F0ue4Y= +github.com/benitogf/ooo v0.0.0-20260202060447-566ed1c50fb9/go.mod h1:fqf1bDkBBOOiCExWW1qdj59ldb/yqfJc3gTfskl02cU= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=