diff --git a/public/city-select.html b/public/city-select.html
index 2cf4144..12ce930 100644
--- a/public/city-select.html
+++ b/public/city-select.html
@@ -265,7 +265,14 @@
}
function selectCity(cityName) {
- window.location.href = `/city/${cityName}`;
+ const urlParams = new URLSearchParams(window.location.search);
+ const fromDashboard = urlParams.get('from') === 'dashboard';
+
+ if (user || fromDashboard) {
+ window.location.href = `/city/${cityName}/dashboard`;
+ } else {
+ window.location.href = `/city/${cityName}`;
+ }
}
function showMessage(message, type = 'success') {
diff --git a/public/dashboard.html b/public/dashboard.html
index 9210f36..922363d 100644
--- a/public/dashboard.html
+++ b/public/dashboard.html
@@ -322,7 +322,7 @@
💧 Water Stations - Loading...
Welcome,
- Change City
+ Change City
diff --git a/public/index.html b/public/index.html
index 5061a94..9dd0c35 100644
--- a/public/index.html
+++ b/public/index.html
@@ -133,8 +133,10 @@
Loading...
- Login
- All Cities
+
@@ -163,6 +165,36 @@
let map;
let stations = [];
let currentCity = null;
+ let user = null;
+
+ async function checkAuth() {
+ try {
+ const response = await fetch('/api/user');
+ const data = await response.json();
+ user = data.user;
+ updateAuthButtons();
+ } catch (error) {
+ console.error('Auth check failed:', error);
+ updateAuthButtons();
+ }
+ }
+
+ function updateAuthButtons() {
+ const loginBtn = document.getElementById('loginBtn');
+ const changeCityBtn = document.getElementById('changeCityBtn');
+
+ if (user) {
+ loginBtn.textContent = 'Dashboard';
+ loginBtn.href = `/city/${currentCity}/dashboard`;
+ changeCityBtn.textContent = 'Change City';
+ changeCityBtn.href = '/city-select';
+ } else {
+ loginBtn.textContent = 'Login';
+ loginBtn.href = `/login?redirect=${encodeURIComponent(window.location.pathname)}`;
+ changeCityBtn.textContent = 'All Cities';
+ changeCityBtn.href = '/city-select';
+ }
+ }
function initMap() {
// Get city name from URL
@@ -184,6 +216,7 @@
attribution: '© OpenStreetMap contributors'
}).addTo(map);
+ checkAuth();
loadStations();
}
@@ -197,6 +230,7 @@
}
displayStations();
fitMapToStations();
+ updateAuthButtons();
})
.catch(error => {
console.error('Error loading stations:', error);
diff --git a/public/login.html b/public/login.html
index 51b8935..491bccf 100644
--- a/public/login.html
+++ b/public/login.html
@@ -211,8 +211,8 @@
or
- Google
- Instagram
+ Google
+ Instagram
- Sign up with Google
- Sign up with Instagram
+ Sign up with Google
+ Sign up with Instagram