feat: create|login on room path
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user