
Replaces the mocked login flow with an actual API call to an authentication endpoint. Updates the `AuthStruct` schema to align with the new API response, including fields for `accessToken`, `dbName`, `uid`, `name`, and `username`. Introduces a `UserConnectedProvider` service for managing the storage and retrieval of authenticated user details, centralizing this logic and replacing prior direct local storage methods. Integrates the new authentication process and user storage service into the login, reception, and profile pages for a unified experience. Adjusts the splash screen duration to reflect the real-time nature of the authentication check.
46 lines
1.6 KiB
Dart
46 lines
1.6 KiB
Dart
import 'package:barcode_scanner/backend/schema/user/user_struct.dart';
|
|
import 'package:barcode_scanner/services/secure_storage.dart';
|
|
import 'package:barcode_scanner/services/token_provider.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'reception_page_model.freezed.dart';
|
|
|
|
final receptionPageModelProvider =
|
|
StateNotifierProvider<ReceptionPageModel, ReceptionPageState>((ref) {
|
|
return ReceptionPageModel(
|
|
secureStorage: ref.read(sharedPrefsProvider),
|
|
tokenProvider: ref.read(tokenProvider),
|
|
userConnectedProvider: ref.read(userConnectedProvider),
|
|
);
|
|
});
|
|
|
|
class ReceptionPageModel extends StateNotifier<ReceptionPageState> {
|
|
/// Constructor initializes the TaskRepository using the provider reference.
|
|
ReceptionPageModel({
|
|
required this.secureStorage,
|
|
required this.tokenProvider,
|
|
required this.userConnectedProvider,
|
|
}) : super(const ReceptionPageState());
|
|
|
|
late FlutterSecureStorage secureStorage;
|
|
late TokenProvider tokenProvider;
|
|
final UserConnectedProvider userConnectedProvider;
|
|
|
|
Future getUserConnected() async {
|
|
state = state.copyWith(loading: true);
|
|
final user = await userConnectedProvider.get();
|
|
state = state.copyWith(user: user, loading: false);
|
|
}
|
|
}
|
|
|
|
@freezed
|
|
abstract class ReceptionPageState with _$ReceptionPageState {
|
|
const factory ReceptionPageState({
|
|
UserStruct? user,
|
|
@Default(false) bool loading,
|
|
}) = _ReceptionPageState;
|
|
}
|