diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-19 21:01:23 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-19 21:01:23 +0200 |
commit | fbcac585cf626917e2baf1d0065c7b632341ba01 (patch) | |
tree | 82a0ca1812f92500588c0503cc80b23cffd159e8 /pkg/ext/middleware.go | |
parent | 52276ba99540d6c61195772ccdd50944e96f4959 (diff) | |
download | lens-fbcac585cf626917e2baf1d0065c7b632341ba01.tar.gz lens-fbcac585cf626917e2baf1d0065c7b632341ba01.tar.bz2 lens-fbcac585cf626917e2baf1d0065c7b632341ba01.zip |
ref: Move auth functions to service
Diffstat (limited to 'pkg/ext/middleware.go')
-rw-r--r-- | pkg/ext/middleware.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pkg/ext/middleware.go b/pkg/ext/middleware.go index 2dd1cca..bcc6c5f 100644 --- a/pkg/ext/middleware.go +++ b/pkg/ext/middleware.go @@ -8,6 +8,7 @@ import ( "github.com/valyala/fasthttp" "git.sr.ht/~gabrielgio/img/pkg/database/repository" + "git.sr.ht/~gabrielgio/img/pkg/service" ) func HTML(next fasthttp.RequestHandler) fasthttp.RequestHandler { @@ -77,7 +78,7 @@ func (a *AuthMiddleware) LoggedIn(next fasthttp.RequestHandler) fasthttp.Request return } - token, err := ReadToken(auth, a.key) + token, err := service.ReadToken(auth, a.key) if err != nil { a.entry.Error(err) ctx.Redirect(redirectLogin, 307) @@ -92,9 +93,9 @@ func (a *AuthMiddleware) LoggedIn(next fasthttp.RequestHandler) fasthttp.Request } } -func GetTokenFromCtx(ctx *fasthttp.RequestCtx) *Token { +func GetTokenFromCtx(ctx *fasthttp.RequestCtx) *service.Token { tokenValue := ctx.UserValue("token") - if token, ok := tokenValue.(*Token); ok { + if token, ok := tokenValue.(*service.Token); ok { return token } return nil @@ -113,7 +114,7 @@ func NewInitialSetupMiddleware(userRepository repository.UserRepository) *Initia func (i *InitialSetupMiddleware) Check(next fasthttp.RequestHandler) fasthttp.RequestHandler { return func(ctx *fasthttp.RequestCtx) { // if user has been set to context it is logged in already - _, ok := ctx.UserValue("token").(*Token) + _, ok := ctx.UserValue("token").(*service.Token) if ok { next(ctx) return |