feat: consolidate backend and docker-compose setup
This commit is contained in:
commit
ff3753a745
306 files changed
+35450
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../core/network/api_client.dart';
|
||||
import '../../config/app_config.dart';
|
||||
|
||||
class AuthNotifier extends StateNotifier<bool> {
|
||||
AuthNotifier() : super(false);
|
||||
|
||||
Future<bool> checkLoginState() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final token = prefs.getString('auth_token');
|
||||
if (token != null) {
|
||||
state = true;
|
||||
return true;
|
||||
}
|
||||
state = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> login(String username, String password) async {
|
||||
final apiClient = ApiClient();
|
||||
try {
|
||||
final response = await apiClient.client.post(
|
||||
AppConfig.loginEndpoint,
|
||||
data: {
|
||||
'username': username,
|
||||
'password': password,
|
||||
},
|
||||
);
|
||||
|
||||
final token = response.data['data']['token'];
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('auth_token', token);
|
||||
|
||||
state = true;
|
||||
} catch (e) {
|
||||
state = false;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove('auth_token');
|
||||
state = false;
|
||||
}
|
||||
}
|
||||
|
||||
final authProvider = StateNotifierProvider<AuthNotifier, bool>((ref) {
|
||||
return AuthNotifier();
|
||||
});
|
||||
Reference in new issue
Block a user