tbs
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 47s

This commit is contained in:
2024-09-17 22:47:54 +02:00
parent 6f22e066ab
commit f184e261ee
5 changed files with 93 additions and 10 deletions

View File

@@ -1,14 +1,17 @@
package handler
import (
"log/slog"
"me-fit/service"
"database/sql"
"net/http"
)
func handleAuth(db *sql.DB, router *http.ServeMux) {
// Don't use auth middleware for these routes, as it makes redirecting very difficult, if the mail is not yet verified
func authUi(db *sql.DB) http.Handler {
router := http.NewServeMux()
router.Handle("/auth/signin", service.HandleSignInPage(db))
router.Handle("/auth/signup", service.HandleSignUpPage(db))
router.Handle("/auth/verify", service.HandleSignUpVerifyPage(db)) // Hint for the user to verify their email
@@ -16,6 +19,19 @@ func handleAuth(db *sql.DB, router *http.ServeMux) {
router.Handle("/auth/verify-email", service.HandleSignUpVerifyResponsePage(db)) // The link contained in the email
router.Handle("/auth/change-password", service.HandleChangePasswordPage(db))
router.Handle("/auth/reset-password", service.HandleResetPasswordPage(db))
router.Handle("/", service.HandleIndexAnd404(db))
// return router
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
slog.Warn(r.URL.Path)
router.ServeHTTP(w, r)
})
}
func authApi(db *sql.DB) http.Handler {
router := http.NewServeMux()
router.Handle("/api/auth/signup", service.HandleSignUpComp(db))
router.Handle("/api/auth/signin", service.HandleSignInComp(db))
router.Handle("/api/auth/signout", service.HandleSignOutComp(db))
@@ -24,4 +40,6 @@ func handleAuth(db *sql.DB, router *http.ServeMux) {
router.Handle("/api/auth/change-password", service.HandleChangePasswordComp(db))
router.Handle("/api/auth/reset-password", service.HandleResetPasswordComp(db))
router.Handle("/api/auth/reset-password-actual", service.HandleActualResetPasswordComp(db))
return router
}