Files
bookhoard/internal/handlers/context.go
T
john-okeefe 00a083b60b Rename backend code references: Bookmann → Bookhoard
Backend changes:
- Update import paths: bookmann/internal → bookhoard/internal
- Rename struct fields: BookmannUUID → BookhoardUUID
- Update handler function names: mapContentIdToBookmannUUID → mapContentIdToBookhoardUUID
- Update HTTP response headers: X-Bookmann-* → X-Bookhoard-*
- Update service and middleware references
- Update main.go imports and references

This is part 2 of the project rename to Bookhoard.
2026-02-01 16:11:54 -05:00

30 lines
924 B
Go

package handlers
import (
"bookhoard/internal/database"
"net/http"
"github.com/labstack/echo/v4"
)
// GetAuthenticatedUser safely retrieves the authenticated user from context
// Returns an error if the user is not found in context or type assertion fails
func GetAuthenticatedUser(c echo.Context) (database.Users, error) {
user, ok := c.Get("user").(database.Users)
if !ok {
return database.Users{}, echo.NewHTTPError(http.StatusInternalServerError, "authentication context error")
}
return user, nil
}
// MustGetAuthenticatedUser gets user or panics
// Only use this after authentication middleware has verified the user
// Panicking here indicates a serious bug in the middleware chain
func MustGetAuthenticatedUser(c echo.Context) database.Users {
user, err := GetAuthenticatedUser(c)
if err != nil {
panic(err) // Should never happen if authentication middleware is working correctly
}
return user
}