feat: Complete platform enhancement with multi-tenant architecture
Major additions: - Territory manager system with application workflow - Custom pricing and page builder with Craft.js - Enhanced Stripe Connect onboarding - CodeReadr QR scanning integration - Kiosk mode for venue sales - Super admin dashboard and analytics - MCP integration for AI-powered operations Infrastructure improvements: - Centralized API client and routing system - Enhanced authentication with organization context - Comprehensive theme management system - Advanced event management with custom tabs - Performance monitoring and accessibility features Database schema updates: - Territory management tables - Custom pages and pricing structures - Kiosk PIN system - Enhanced organization profiles - CodeReadr integration tables 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
65
src/pages/api/auth/login.ts
Normal file
65
src/pages/api/auth/login.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { createSupabaseServerClient } from '../../../lib/supabase-ssr';
|
||||
|
||||
export const POST: APIRoute = async ({ request, cookies }) => {
|
||||
try {
|
||||
const formData = await request.json();
|
||||
const { email, password } = formData;
|
||||
|
||||
if (!email || !password) {
|
||||
return new Response(JSON.stringify({
|
||||
error: 'Email and password are required'
|
||||
}), {
|
||||
status: 400,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
|
||||
const supabase = createSupabaseServerClient(cookies);
|
||||
|
||||
const { data, error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return new Response(JSON.stringify({
|
||||
error: error.message
|
||||
}), {
|
||||
status: 401,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
|
||||
// Get user organization
|
||||
const { data: userData } = await supabase
|
||||
.from('users')
|
||||
.select('organization_id, role, is_super_admin')
|
||||
.eq('id', data.user.id)
|
||||
.single();
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
user: data.user,
|
||||
organizationId: userData?.organization_id,
|
||||
isAdmin: userData?.role === 'admin',
|
||||
isSuperAdmin: userData?.role === 'admin' && userData?.is_super_admin === true,
|
||||
redirectTo: !userData?.organization_id
|
||||
? '/onboarding/organization'
|
||||
: userData?.role === 'admin'
|
||||
? '/admin/dashboard'
|
||||
: '/dashboard'
|
||||
}), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
return new Response(JSON.stringify({
|
||||
error: 'An error occurred during login'
|
||||
}), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user