feat: private posts
All checks were successful
Release / publish (push) Successful in 2m41s

This commit is contained in:
2025-10-17 23:51:19 +02:00
parent 68574ad289
commit 893c49ec88
15 changed files with 154 additions and 15 deletions

View File

@@ -8,11 +8,16 @@ import (
)
// Authenticated: This function is a middleware that authenticates incoming HTTP requests using JWT tokens and role-based access control.
func (s *Service) Authenticated(next http.HandlerFunc, roles ...model.Role) http.Handler {
func (s *Service) Authenticated(next http.HandlerFunc, mustauth bool, roles ...model.Role) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Our middleware logic goes here...
token, err := extractToken(r)
if err != nil {
if !mustauth {
r = writeToContext(r, nil)
next(w, r)
return
}
w.WriteHeader(http.StatusUnauthorized)
return
}