galt #1

Merged
bartha.gabor merged 19 commits from galt into main 2025-10-20 08:06:40 +02:00
2 changed files with 10 additions and 5 deletions
Showing only changes of commit d936175de8 - Show all commits

View File

@@ -114,14 +114,14 @@ func (app *App) HandleAdminDeleteOrder(w http.ResponseWriter, r *http.Request) {
} }
func (app *App) HandleGetUsers(w http.ResponseWriter, r *http.Request) { func (app *App) HandleGetUsers(w http.ResponseWriter, r *http.Request) {
rows, err := app.DB.Query("SELECT id, username, role FROM users ORDER BY id") rows, err := app.DB.Query("SELECT id, username, role FROM users WHERE username != 'superadmin' ORDER BY id")
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
defer rows.Close() defer rows.Close()
var users []map[string]any users := make([]map[string]any, 0)
for rows.Next() { for rows.Next() {
var id, role int var id, role int
var username string var username string

View File

@@ -71,9 +71,14 @@ export default function AdminPage() {
fetch(`${API_URL}/api/me`, { fetch(`${API_URL}/api/me`, {
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
}) })
.then((res) => res.json()) .then((res) => {
.then((data) => { console.log(res);
if (!data.role || data.role > 1) { return res.json();
})
.then((data: { role?: number; username?: string }) => {
if (data.role == undefined || data.role > 1) {
console.log(data);
console.log("Not admin, redirecting");
router.push("/landing"); router.push("/landing");
} }
}) })