refactor: Set the current user in the request for VerifyJwt middleware

This commit is contained in:
Derrick Hammer 2023-06-09 07:38:21 -04:00
parent a9d153a22f
commit 40309311bd
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"git.lumeweb.com/LumeWeb/portal/service/account"
"git.lumeweb.com/LumeWeb/portal/service/auth" "git.lumeweb.com/LumeWeb/portal/service/auth"
"github.com/kataras/iris/v12" "github.com/kataras/iris/v12"
) )
@ -13,8 +14,15 @@ func VerifyJwt(ctx iris.Context) {
return return
} }
if err := auth.VerifyLoginToken(token); err != nil { acct, err := auth.VerifyLoginToken(token)
if err != nil {
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken) ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
return return
} }
err = ctx.SetUser(account.NewUser(acct))
if err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
}
} }