fix: Remove client-side auth redirects causing dashboard flashing
- Removed checkAuth() function and redirects from dashboard.astro - Removed checkAuth() function and redirects from events/new.astro - Updated to use Astro.cookies for better SSR compatibility - Client-side code now focuses on data loading, not authentication - Server-side unified auth system handles all protection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -351,26 +351,23 @@ if (!auth) {
|
||||
}, 8000);
|
||||
}
|
||||
|
||||
// Check authentication and redirect immediately if no session
|
||||
async function checkAuth() {
|
||||
const { data: { session } } = await supabase.auth.getSession();
|
||||
if (!session) {
|
||||
// No session found, redirecting to login
|
||||
window.location.href = '/login';
|
||||
return null;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
// Note: Authentication is now handled server-side by unified auth system
|
||||
|
||||
// Load events
|
||||
async function loadEvents() {
|
||||
try {
|
||||
// Check if user has organization_id or is admin
|
||||
// Get current user (auth already verified server-side)
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
// User is null, redirecting to login
|
||||
window.location.href = '/login';
|
||||
// This shouldn't happen due to server-side auth, but handle gracefully
|
||||
console.error('No user found despite server-side auth');
|
||||
loading.innerHTML = `
|
||||
<div class="rounded-xl p-6 max-w-md mx-auto" style="background: var(--error-bg); border: 1px solid var(--error-border);">
|
||||
<p class="font-medium" style="color: var(--error-color);">Session error</p>
|
||||
<p class="text-sm mt-2" style="color: var(--error-color); opacity: 0.8;">Please refresh the page</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -830,9 +827,6 @@ if (!auth) {
|
||||
// Handle onboarding success on page load
|
||||
handleOnboardingSuccess();
|
||||
|
||||
checkAuth().then(session => {
|
||||
if (session) {
|
||||
loadEvents();
|
||||
}
|
||||
});
|
||||
// Load events directly (auth already verified server-side)
|
||||
loadEvents();
|
||||
</script>
|
||||
Reference in New Issue
Block a user