feat: SSE bs into room

This commit is contained in:
efim
2023-11-05 15:00:36 +00:00
parent 648d3dff80
commit bb89b8ccf5
6 changed files with 173 additions and 4 deletions

View File

@@ -33,8 +33,13 @@ const authCookieName = "auth"
const loginPath = "/login"
type contextKey string
func getContextSession(ctx context.Context) sessions.SessionData {
return ctx.Value(contextKey("session")).(sessions.SessionData)
func getContextSession(ctx context.Context) (sessions.SessionData, bool) {
val := ctx.Value(contextKey("session"))
if val == nil {
return sessions.SessionData{}, false
} else {
return ctx.Value(contextKey("session")).(sessions.SessionData), true
}
}
// checks sessionId from cookie
@@ -77,7 +82,7 @@ func authedPageMiddleware(
}
func renderLoginPage(w http.ResponseWriter) {
var templFile = "templates/login.gohtml"
templFile := "templates/login.gohtml"
tmpl := template.Must(template.ParseFS(templateFs, templFile))
err := tmpl.Execute(w, nil)
if err != nil {