Add leads handlers, WhatsApp integration, and test files
This commit is contained in:
@@ -200,12 +200,22 @@ func GetAccountID(r *http.Request) (int64, error) {
|
||||
func requireAuth(w http.ResponseWriter, r *http.Request) (int64, bool) {
|
||||
accountID, err := getSession(r)
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/auth/login", http.StatusFound)
|
||||
if isAPIRequest(r) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(`{"error":"unauthorized"}`))
|
||||
} else {
|
||||
http.Redirect(w, r, "/auth/login", http.StatusFound)
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
return accountID, true
|
||||
}
|
||||
|
||||
func isAPIRequest(r *http.Request) bool {
|
||||
accept := r.Header.Get("Accept")
|
||||
return accept == "application/json" || r.URL.Path == "/leads/qr"
|
||||
}
|
||||
|
||||
func SetupAuthHandlers(db *sql.DB) {
|
||||
DB = db
|
||||
chi.RegisterMethod("GET")
|
||||
|
||||
Reference in New Issue
Block a user