2024-08-11 10:01:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SessionLoad(next http.Handler) http.Handler {
|
|
|
|
return session.LoadAndSave(next)
|
|
|
|
}
|
2024-08-20 19:45:13 +00:00
|
|
|
|
|
|
|
func (app *application) Auth(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !app.Session.Exists(r.Context(), "userID") {
|
|
|
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|