feat: create|login on room path

This commit is contained in:
efim
2023-11-18 13:41:54 +00:00
parent c8f28bf0de
commit d87c102d95
4 changed files with 32 additions and 23 deletions

View File

@@ -25,9 +25,7 @@ func registerPageRoutes(
roomsM rooms.RoomManager,
) {
http.Handle(roomPath, // ending in / captures all following path sections, i.e room name
authedPageMiddleware(
sessionSM,
http.StripPrefix(roomPath, roomPageRoute(templateFs, roomsM))))
http.StripPrefix(roomPath, roomPageRoute(templateFs, roomsM, sessionSM)))
http.Handle(raiseHandPath, // ending in / captures all following path sections, i.e gesture num
authedPageMiddleware(
@@ -165,6 +163,7 @@ func releaseHandRoute(
func roomPageRoute(
templateFs *embed.FS,
roomsM rooms.RoomManager,
sessionSM sessions.SessionManagement,
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
roomName := r.URL.Path
@@ -176,24 +175,16 @@ func roomPageRoute(
}
// check session,
session, found := getContextSession(r.Context())
if !found {
log.Printf("session not found %t", found)
// TODO here will be rendering of
// 'create this room' or 'join this room'
// but yeah, let's just use auth middle that redirects to /
w.Header().Add("HX-Redirect", "/")
return
}
if session.RoomId != roomName {
log.Printf("session found %+v, but for wrong room, trying to access %s", session, roomName)
w.Header().Add("HX-Redirect", "/")
session, err := getRequestSession(r, sessionSM)
if err != nil || session.RoomId != roomName {
log.Printf("not authed with session %+v | error %s, but for wrong room, trying to access %s", session, err, roomName)
renderLoginPage(w, roomName)
return
}
room, found, err := roomsM.Get(roomName)
if err != nil || !found {
log.Printf("/room room for name %s not found or err: %s / found %s", roomName, err, found)
log.Printf("/room room for name %s not found or err: %s / found %t", roomName, err, found)
// TODO here should be append to error place
w.Header().Add("HX-Redirect", "/")
return