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:
2025-07-12 20:40:11 -06:00
parent 76d27590fb
commit 425dfc9348
3 changed files with 322 additions and 29 deletions

View File

@@ -7,7 +7,7 @@ import { verifyAuth } from '../../lib/auth';
export const prerender = false;
// Server-side authentication check
const auth = await verifyAuth(Astro.request);
const auth = await verifyAuth(Astro.cookies);
if (!auth) {
return Astro.redirect('/login');
}
@@ -322,11 +322,12 @@ if (!auth) {
// let selectedAddons: any[] = []; // TODO: Implement addons functionality
let eventImageUrl: string | null = null;
// Check authentication
async function checkAuth() {
const { data: { session } } = await supabase.auth.getSession();
if (!session) {
window.location.href = '/';
// Load user data (auth already verified server-side)
async function loadUserData() {
const { data: { user: authUser } } = await supabase.auth.getUser();
if (!authUser) {
console.error('No user found despite server-side auth');
return null;
}
@@ -334,14 +335,14 @@ if (!auth) {
const { data: user } = await supabase
.from('users')
.select('name, email, organization_id, role')
.eq('id', session.user.id)
.eq('id', authUser.id)
.single();
if (user) {
currentOrganizationId = user.organization_id;
}
return session;
return authUser;
}
// Generate slug from title
@@ -552,9 +553,9 @@ if (!auth) {
}
}
// Initialize
checkAuth().then(session => {
if (session && currentOrganizationId) {
// Initialize (auth already verified server-side)
loadUserData().then(user => {
if (user && currentOrganizationId) {
loadVenues();
}
handleVenueOptionChange(); // Set initial state