fixed some login and booking bugs

This commit is contained in:
tumillanino
2025-10-28 13:36:05 +11:00
parent dad3ec655f
commit 5d7f0a8eb3
11 changed files with 402 additions and 141 deletions

View File

@@ -4,6 +4,9 @@ import (
"database/sql"
"encoding/json"
"net/http"
"os"
ory "github.com/ory/client-go"
)
func sqlNullString(s string) sql.NullString {
@@ -13,6 +16,13 @@ func sqlNullString(s string) sql.NullString {
return sql.NullString{String: s, Valid: true}
}
func nullStringToString(ns sql.NullString) string {
if ns.Valid {
return ns.String
}
return ""
}
func sqlNullUUID(s string) sql.NullString {
if s == "" {
return sql.NullString{}
@@ -24,3 +34,24 @@ func writeJSON(w http.ResponseWriter, v interface{}) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(v)
}
func getOryAPIURL() string {
oryAPIURL := os.Getenv("ORY_API_URL")
if oryAPIURL == "" {
tunnelPort := os.Getenv("TUNNEL_PORT")
if tunnelPort == "" {
tunnelPort = "4000"
}
oryAPIURL = "http://localhost:" + tunnelPort
}
return oryAPIURL
}
func isAuthenticated(r *http.Request, oryClient *ory.APIClient) bool {
cookies := r.Header.Get("Cookie")
session, _, err := oryClient.FrontendAPI.ToSession(r.Context()).Cookie(cookies).Execute()
if err != nil {
return false
}
return session != nil && session.Active != nil && *session.Active
}