Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2022-09-27 02:50:07 +08:00
commit 7cf10b07d4
44 changed files with 4569 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package user
import (
"context"
"errors"
"net/http"
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/common"
"github.com/go-chi/render"
)
func (env *Env) CheckUserMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie(env.CookieString)
if err != nil {
err = errors.New("user not logged in")
render.Render(w, r, common.ErrInternalError(err))
return
}
user, err := env.getUserFromSessionToken(cookie.Value)
if err != nil {
render.Render(w, r, common.ErrInternalError(err))
return
}
ctx := context.WithValue(r.Context(), UserContextKey, user)
next.ServeHTTP(w, r.WithContext(ctx))
})
}