Added reauthentication (token freshness) and protected username change

This commit is contained in:
2025-02-15 20:12:30 +11:00
parent 6bee6edd16
commit 42ea74fd63
10 changed files with 315 additions and 14 deletions

View File

@@ -0,0 +1,21 @@
package middleware
import (
"net/http"
"projectreshoot/contexts"
"time"
)
func RequiresFresh(
next http.Handler,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user := contexts.GetUser(r.Context())
isFresh := time.Now().Before(time.Unix(user.Fresh, 0))
if !isFresh {
w.WriteHeader(444)
return
}
next.ServeHTTP(w, r)
})
}