Skip to content

Commit

Permalink
website: fix login middleware failing due to wrong HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jan 28, 2024
1 parent 940979c commit 904d1ea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions website/admin/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func Router(ctx context.Context, s State) chi.Router {

r.Group(func(r chi.Router) {
r.Use(s.Authentication.LoginMiddleware)
r.Get("/", s.GetHome)
r.HandleFunc("/", s.GetHome)
r.Get("/profile", s.GetProfile)
r.Post("/profile", s.PostProfile)
r.Get("/pending", s.GetPending)
r.Get("/streamer/start", s.StartStreamer)
r.Get("/streamer/stop", s.StopStreamer)
r.HandleFunc("/pending", s.GetPending)
r.HandleFunc("/streamer/start", s.StartStreamer)
r.HandleFunc("/streamer/stop", s.StopStreamer)
})

return r
Expand Down
4 changes: 1 addition & 3 deletions website/middleware/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (a authentication) UserMiddleware(next http.Handler) http.Handler {

// no known username
if username == "" {
next.ServeHTTP(w, r)
next.ServeHTTP(w, RequestWithUser(r, nil))
return
}

Expand Down Expand Up @@ -331,8 +331,6 @@ func UserFromContext(ctx context.Context) *radio.User {
u, ok := ctx.Value(userContextKey).(*radio.User)
if !ok {
panic("UserFromContext: called from handler not behind LoginMiddleware")
} else if u == nil {
panic("UserFromContext: someone stored a nil user")
}
return u
}
Expand Down
1 change: 0 additions & 1 deletion website/public/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type shared struct {

func Router(ctx context.Context, s State) chi.Router {
r := chi.NewRouter()
r.Use(middleware.ThemeCtx(s.Storage))

r.Get("/", s.GetHome)
r.Get("/news", s.GetNews)
Expand Down

0 comments on commit 904d1ea

Please sign in to comment.