Skip to content

Authentication Failure with Supabase/Google OAuth #101 #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ Replace placeholders with actual values from **Supabase** and **Google Cloud Con
- Professional certifications
- Background verification
- Admin approval process before full platform access
### Troubleshooting
- **Flutter run fails with "Supabase not initialized"**: Ensure `.env` file exists in `patient/` and `therapist/` with correct `SUPABASE_URL` and `SUPABASE_ANON_KEY`.
- **Google OAuth redirect fails**: Double-check the redirect URI in Google Cloud Console matches `https://your-project-id.supabase.co/auth/v1/callback`.
- **Dependencies not found**: Run `flutter pub get` in both `patient/` and `therapist/` directories.

### Patient Management

Expand Down
46 changes: 27 additions & 19 deletions patient/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ import 'package:patient/provider/appointments_provider.dart';
import 'package:patient/provider/assessment_provider.dart';
import 'package:patient/provider/auth_provider.dart';
import 'package:patient/repository/supabase_auth_repository.dart';

import 'package:patient/provider/reports_provider.dart';

import 'package:patient/provider/task_provider.dart';
import 'package:provider/provider.dart';
import 'package:supabase_flutter/supabase_flutter.dart';



import 'core/theme/theme.dart';
import 'presentation/splash_screen.dart';
import 'provider/assessment_provider.dart';

import 'provider/task_provider.dart';


Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

// Load environment variables from .env file
await dotenv.load(fileName: ".env");

// Validate that Supabase credentials are present
final supabaseUrl = dotenv.env['SUPABASE_URL'];
final supabaseAnonKey = dotenv.env['SUPABASE_ANON_KEY'];
if (supabaseUrl == null || supabaseAnonKey == null) {
throw Exception('Supabase URL or Anon Key missing in .env file');
}

// Initialize Supabase
await Supabase.initialize(
url: dotenv.env['SUPABASE_URL']!,
anonKey: dotenv.env['SUPABASE_ANON_KEY']!,
url: supabaseUrl,
anonKey: supabaseAnonKey,
);

// Set system UI overlay style
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.white,
Expand All @@ -53,7 +55,7 @@ Future<void> main() async {
),
ChangeNotifierProvider(create: (_) => ReportsProvider()),
ChangeNotifierProvider(create: (_) => TaskProvider()),
ChangeNotifierProvider(create: (_) => AppointmentsProvider())
ChangeNotifierProvider(create: (_) => AppointmentsProvider()),
],
child: const MyApp(),
),
Expand All @@ -66,10 +68,16 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: SnackbarService.scaffoldMessengerKey,
debugShowCheckedModeBanner: false,
title: 'Patient App',
theme: AppTheme.lightTheme(),
home: const SplashScreen());
scaffoldMessengerKey: SnackbarService.scaffoldMessengerKey, // Global key for SnackBar
debugShowCheckedModeBanner: false,
title: 'Patient App',
theme: AppTheme.lightTheme(),
home: const SplashScreen(),
// Define named routes if needed (e.g., for navigation after onboarding)
routes: {
'/home': (context) => const Placeholder(), // Replace with actual home screen
'/login': (context) => const Placeholder(), // Replace with actual login screen
},
);
}
}
43 changes: 43 additions & 0 deletions patient/lib/onboarding_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});

@override
_SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_checkUserStatus();
}

Future<void> _checkUserStatus() async {
final authProvider = Provider.of<AuthProvider>(context, listen: false);
await Future.delayed(const Duration(seconds: 2)); // Simulate splash delay
if (authProvider.isAuthenticated) {
final profile = await Supabase.instance.client
.from('profiles')
.select()
.eq('user_id', authProvider.user!.id)
.maybeSingle();
if (profile == null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const OnboardingScreen()),
);
} else {
Navigator.pushReplacementNamed(context, '/home');
}
} else {
Navigator.pushReplacementNamed(context, '/login');
}
}

@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Text('NeuroTrack')),
);
}
}
3 changes: 2 additions & 1 deletion supabase/scripts/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SUPABASE_URL="your-supabase-url"
SUPABASE_KEY="your-supabase-key"

GOOGLE_WEB_CLIENT_ID="your_web_client_id"
GOOGLE_SECRET_KEY="your_secret_key"