Skip to content

Commit

Permalink
add delete account endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoSchw committed Oct 3, 2024
1 parent 52b40c7 commit c51fe47
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
30 changes: 30 additions & 0 deletions internal/auth/handler/delete_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package handler

import (
"encoding/json"
"net/http"

"github.com/shigde/sfu/internal/auth"
"github.com/shigde/sfu/internal/rest"
)

func DeleteAccount(accountService *auth.AccountService) http.HandlerFunc {

return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
user, err := getJsonAuthPayload(w, r)
if err != nil {
rest.HttpError(w, "", http.StatusBadRequest, err)
return
}

token, err := accountService.GetAuthToken(r.Context(), user)
if err != nil {
rest.HttpError(w, "error reading stream list", http.StatusNotFound, err)
return
}
if err := json.NewEncoder(w).Encode(token); err != nil {
rest.HttpError(w, "error reading stream list", http.StatusInternalServerError, err)
}
}
}
7 changes: 4 additions & 3 deletions internal/auth/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ func UseRoutes(router *mux.Router, accountService *AccountService) {
router.HandleFunc("/authenticate", handler.Authentication(accountService)).Methods("POST")
router.HandleFunc("/auth/login", handler.Login(accountService)).Methods("POST")
router.HandleFunc("/auth/register", handler.Register(accountService)).Methods("POST")
router.HandleFunc("/auth/forgotpassword", handler.ForgotPassword(accountService)).Methods("POST")
router.HandleFunc("/auth/newpassword", handler.NewPassword(accountService)).Methods("POST")
router.HandleFunc("/auth/verify", handler.Verification(accountService)).Methods("POST")
router.HandleFunc("/auth/forgotPassword", handler.ForgotPassword(accountService)).Methods("POST")
router.HandleFunc("/auth/newPassword", handler.NewPassword(accountService)).Methods("POST")
router.HandleFunc("/auth/deleteAccount", handler.DeleteAccount(accountService)).Methods("POST")
router.HandleFunc("/auth/verify/{token}", handler.Verification(accountService)).Methods("GET")
}

0 comments on commit c51fe47

Please sign in to comment.