aaa
This commit is contained in:
@@ -39,6 +39,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
final success = await ref.read(authProvider.notifier).login(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
rememberMe: _rememberMe,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
@@ -86,29 +86,36 @@ class Auth extends _$Auth {
|
||||
|
||||
/// Initialize auth state - call this on app start
|
||||
Future<void> initialize() async {
|
||||
print('🚀 Initializing auth state...');
|
||||
state = state.copyWith(isLoading: true);
|
||||
|
||||
final isAuthenticated = await _repository.isAuthenticated();
|
||||
print('🚀 isAuthenticated result: $isAuthenticated');
|
||||
|
||||
if (isAuthenticated) {
|
||||
print('🚀 Token found, fetching user profile...');
|
||||
// Get user profile
|
||||
final result = await _repository.getProfile();
|
||||
result.fold(
|
||||
(failure) {
|
||||
print('❌ Failed to get profile: ${failure.message}');
|
||||
state = const AuthState(
|
||||
isAuthenticated: false,
|
||||
isLoading: false,
|
||||
);
|
||||
},
|
||||
(user) {
|
||||
print('✅ Profile loaded: ${user.name}');
|
||||
state = AuthState(
|
||||
user: user,
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
);
|
||||
print('✅ Initialize complete: isAuthenticated=${state.isAuthenticated}');
|
||||
},
|
||||
);
|
||||
} else {
|
||||
print('❌ No token found, user needs to login');
|
||||
state = const AuthState(
|
||||
isAuthenticated: false,
|
||||
isLoading: false,
|
||||
@@ -120,10 +127,15 @@ class Auth extends _$Auth {
|
||||
Future<bool> login({
|
||||
required String email,
|
||||
required String password,
|
||||
bool rememberMe = false,
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true, clearError: true);
|
||||
|
||||
final result = await _repository.login(email: email, password: password);
|
||||
final result = await _repository.login(
|
||||
email: email,
|
||||
password: password,
|
||||
rememberMe: rememberMe,
|
||||
);
|
||||
|
||||
return result.fold(
|
||||
(failure) {
|
||||
|
||||
Reference in New Issue
Block a user