fix: more refactoring #181
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 2m8s
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 2m8s
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"me-fit/utils"
|
||||
|
||||
"context"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func EnsureValidSession(db *sql.DB, next http.Handler) http.Handler {
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user := utils.GetUserFromSession(db, r)
|
||||
if user == nil {
|
||||
utils.DoRedirect(w, r, "/auth/signin")
|
||||
return
|
||||
}
|
||||
|
||||
if !user.EmailVerified && r.URL.Path != "/auth/verify" {
|
||||
utils.DoRedirect(w, r, "/auth/verify")
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), utils.ContextKeyUser, user)
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user