2019-09-28 20:04:51 -04:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
func IsAuthenticated(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
|
|
|
|
|
|
session, err := Store.Get(r, "auth-session")
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := session.Values["profile"]; !ok {
|
2019-09-29 15:30:24 -04:00
|
|
|
//TODO allow customization of redirect
|
2019-09-28 20:04:51 -04:00
|
|
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
|
|
} else {
|
|
|
|
next(w, r)
|
|
|
|
}
|
|
|
|
}
|