Skip to content

Commit c414324

Browse files
authored
Merge pull request #14 from jnnabugwu/dev
fix: fixing deployment
2 parents 6052517 + 4852eb4 commit c414324

File tree

2 files changed

+81
-60
lines changed

2 files changed

+81
-60
lines changed

lib/core/config/supabase_config.dart

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,38 @@ import 'package:flutter/foundation.dart';
22
import 'package:flutter_dotenv/flutter_dotenv.dart';
33
import 'package:supabase_flutter/supabase_flutter.dart';
44
import 'dart:js' as js;
5+
import '../../utils/environment.dart';
56

67
class SupabaseConfig {
78
static String get supabaseUrl {
89
try {
9-
if (kIsWeb) {
10-
if (js.context['ENV'] == null) {
11-
debugPrint('❌ ERROR: window.ENV is not defined! Check if config.js is loaded');
12-
throw Exception('window.ENV is not defined');
13-
}
14-
final env = js.context['ENV'];
15-
if (env['SUPABASE_URL'] == null) {
16-
debugPrint('❌ ERROR: SUPABASE_URL not found in window.ENV');
17-
throw Exception('SUPABASE_URL not found in config');
18-
}
19-
final url = env['SUPABASE_URL'] as String;
20-
debugPrint('✅ Loaded Supabase URL from web config: $url');
21-
return url;
22-
}
23-
return dotenv.env['SUPABASE_URL'] ?? '';
10+
// Use our Environment utility class that has fallbacks
11+
return Environment.supabaseUrl;
2412
} catch (e) {
2513
debugPrint('❌ Error getting Supabase URL: $e');
26-
rethrow;
14+
// Return fallback directly here as a last resort
15+
return 'https://kszcjniwbqxyndpsajhr.supabase.co/';
2716
}
2817
}
2918

3019
static String get supabaseAnonKey {
3120
try {
32-
if (kIsWeb) {
33-
if (js.context['ENV'] == null) {
34-
debugPrint('❌ ERROR: window.ENV is not defined! Check if config.js is loaded');
35-
throw Exception('window.ENV is not defined');
36-
}
37-
final env = js.context['ENV'];
38-
if (env['SUPABASE_ANON_KEY'] == null) {
39-
debugPrint('❌ ERROR: SUPABASE_ANON_KEY not found in window.ENV');
40-
throw Exception('SUPABASE_ANON_KEY not found in config');
41-
}
42-
final key = env['SUPABASE_ANON_KEY'] as String;
43-
debugPrint('✅ Loaded Supabase Anon Key from web config');
44-
return key;
45-
}
46-
return dotenv.env['SUPABASE_ANON_KEY'] ?? '';
21+
// Use our Environment utility class that has fallbacks
22+
return Environment.supabaseAnonKey;
4723
} catch (e) {
4824
debugPrint('❌ Error getting Supabase Anon Key: $e');
49-
rethrow;
25+
// Return fallback directly here as a last resort
26+
return 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtzemNqbml3YnF4eW5kcHNhamhyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDM2NTEzNjQsImV4cCI6MjA1OTIyNzM2NH0.UnN4xuo783XDrR5nQTlwZAIcW6DqrbFY3bo4nssOvu4';
5027
}
5128
}
5229

5330
static Future<void> initialize() async {
5431
try {
5532
if (!kIsWeb) {
56-
await dotenv.load();
33+
await dotenv.load().catchError((e) {
34+
debugPrint('⚠️ Warning: Could not load .env file: $e');
35+
debugPrint('Using fallback values instead');
36+
});
5737
}
5838

5939
final url = supabaseUrl;
@@ -63,18 +43,22 @@ class SupabaseConfig {
6343
debugPrint('📍 URL Length: ${url.length}');
6444
debugPrint('🔑 Key Length: ${key.length}');
6545

46+
if (url.isEmpty || key.isEmpty) {
47+
throw AssertionError('Supabase URL or Anon Key is empty. Check your configuration.');
48+
}
49+
6650
await Supabase.initialize(
6751
url: url,
6852
anonKey: key,
69-
debug: true,
53+
debug: kDebugMode,
7054
);
7155

7256
// Test the connection
7357
final client = Supabase.instance.client;
7458
debugPrint('🔍 Testing connection...');
7559
try {
7660
// Simple test query that should always work
77-
await client.from('_dummy_test').select().limit(1);
61+
await client.from('athletes').select('id').limit(1);
7862
debugPrint('✅ Connection test successful!');
7963
} catch (e) {
8064
debugPrint('⚠️ Connection test failed: $e');

lib/main.dart

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,86 @@ import 'package:flutter/material.dart';
33
import 'package:supabase_flutter/supabase_flutter.dart';
44
import 'package:athlete_alumni/core/di/injection.dart' as di;
55
import 'package:athlete_alumni/core/router/app_router.dart';
6-
import 'package:flutter_dotenv/flutter_dotenv.dart';
6+
import 'package:athlete_alumni/utils/environment.dart';
7+
import 'package:athlete_alumni/core/config/supabase_config.dart';
78

89
void main() async {
910
WidgetsFlutterBinding.ensureInitialized();
1011

11-
// Load .env file first
1212
try {
13-
await dotenv.load(fileName: ".env");
14-
print('✅ Loaded .env file successfully');
15-
16-
// Get and log Supabase configuration (without the actual key)
17-
final supabaseUrl = dotenv.get('SUPABASE_URL');
18-
print('🔍 Supabase URL configured as: $supabaseUrl');
13+
// Initialize environment variables first
14+
await Environment.initialize();
15+
if (kDebugMode) {
16+
print('✅ Environment initialized successfully');
17+
18+
// Get and log Supabase configuration
19+
final supabaseUrl = Environment.supabaseUrl;
20+
print('🔍 Supabase URL configured as: $supabaseUrl');
21+
print('🔍 URL length: ${supabaseUrl.length}');
22+
}
1923

20-
// Initialize Supabase
21-
await Supabase.initialize(
22-
url: supabaseUrl,
23-
anonKey: dotenv.get('SUPABASE_ANON_KEY'),
24-
);
25-
print('✅ Supabase initialized successfully');
24+
// Initialize Supabase using our config
25+
await SupabaseConfig.initialize();
26+
if (kDebugMode) {
27+
print('✅ Supabase initialized successfully');
28+
}
2629

2730
// Initialize dependency injection
2831
await di.init();
29-
print('✅ Dependency injection initialized');
32+
if (kDebugMode) {
33+
print('✅ Dependency injection initialized');
34+
}
3035

3136
runApp(const MyApp());
3237

33-
} catch (e) {
34-
print('❌ Error during initialization:');
35-
print('Error type: ${e.runtimeType}');
36-
print('Error details: $e');
37-
38-
if (e is Error) {
39-
print('Stack trace: ${e.stackTrace}');
38+
} catch (e, stackTrace) {
39+
if (kDebugMode) {
40+
print('❌ Error during initialization:');
41+
print('Error type: ${e.runtimeType}');
42+
print('Error details: $e');
43+
print('Stack trace: $stackTrace');
4044
}
4145

4246
// Show error UI instead of crashing
4347
runApp(MaterialApp(
4448
home: Scaffold(
4549
body: Center(
46-
child: Text(
47-
'Error initializing app: ${e.toString()}',
48-
style: const TextStyle(color: Colors.red),
50+
child: Padding(
51+
padding: const EdgeInsets.all(20.0),
52+
child: Column(
53+
mainAxisAlignment: MainAxisAlignment.center,
54+
children: [
55+
const Icon(
56+
Icons.error_outline,
57+
color: Colors.red,
58+
size: 60,
59+
),
60+
const SizedBox(height: 20),
61+
Text(
62+
'Error initializing app:',
63+
style: const TextStyle(
64+
color: Colors.red,
65+
fontSize: 18,
66+
fontWeight: FontWeight.bold,
67+
),
68+
),
69+
const SizedBox(height: 10),
70+
Text(
71+
e.toString(),
72+
style: const TextStyle(color: Colors.red),
73+
textAlign: TextAlign.center,
74+
),
75+
const SizedBox(height: 30),
76+
ElevatedButton(
77+
onPressed: () {
78+
// This is a simple restart attempt
79+
// In a real app, you'd want a more robust solution
80+
main();
81+
},
82+
child: const Text('Try Again'),
83+
),
84+
],
85+
),
4986
),
5087
),
5188
),

0 commit comments

Comments
 (0)