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>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user