chore(auth): more refactoring
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 46s

This commit is contained in:
2024-09-19 21:33:20 +02:00
parent bb9381433b
commit f83a404206
3 changed files with 334 additions and 286 deletions

View File

@@ -21,17 +21,17 @@ func GetHandler(db *sql.DB) http.Handler {
router.Handle("/auth/", authUi(db))
router.Handle("/api/auth/", authApi(db))
router.Handle("/workout", auth(db, workoutUi(db)))
router.Handle("/api/workout", auth(db, workoutApi(db)))
router.Handle("/workout", authMiddleware(db, workoutUi(db)))
router.Handle("/api/workout", authMiddleware(db, workoutApi(db)))
// Needed a second time with trailing slash, otherwise either /api/workout or /api/workout/{id} does not match
router.Handle("/api/workout/", auth(db, workoutApi(db)))
router.Handle("/api/workout/", authMiddleware(db, workoutApi(db)))
return middleware.Logging(
middleware.EnableCors(
router))
}
func auth(db *sql.DB, h http.Handler) http.Handler {
func authMiddleware(db *sql.DB, h http.Handler) http.Handler {
return middleware.EnsureValidSession(db, h)
}