From fbcac585cf626917e2baf1d0065c7b632341ba01 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Wed, 19 Jul 2023 21:01:23 +0200 Subject: ref: Move auth functions to service --- pkg/ext/middleware.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pkg/ext/middleware.go') 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 -- cgit v1.2.3