Signed-off-by: Nikolai Rodionov <allanger@posteo.de>
This commit is contained in:
@@ -7,20 +7,14 @@ import 'package:softplayer_web/features/authorization/application/sign_in_data.d
|
||||
import 'package:softplayer_web/features/authorization/application/sign_up_data.dart';
|
||||
|
||||
class AuthState {
|
||||
final AuthMode mode;
|
||||
final bool isAuthorized;
|
||||
|
||||
const AuthState({this.mode = AuthMode.login, this.isAuthorized = false});
|
||||
AuthState copyWith({AuthMode? mode, String? status, bool? isAuthorized}) {
|
||||
return AuthState(
|
||||
mode: mode ?? this.mode,
|
||||
isAuthorized: isAuthorized ?? this.isAuthorized,
|
||||
);
|
||||
const AuthState({this.isAuthorized = false});
|
||||
AuthState copyWith({bool? isAuthorized}) {
|
||||
return AuthState(isAuthorized: isAuthorized ?? this.isAuthorized);
|
||||
}
|
||||
}
|
||||
|
||||
enum AuthMode { login, signup }
|
||||
|
||||
final authorizationControllerProvider =
|
||||
AsyncNotifierProvider<AuthorizationController, AuthState>(
|
||||
AuthorizationController.new,
|
||||
@@ -29,9 +23,6 @@ final authorizationControllerProvider =
|
||||
class AuthorizationController extends AsyncNotifier<AuthState> {
|
||||
@override
|
||||
Future<AuthState> build() async {
|
||||
// Use is considered authorized if tokens are set in the memory.
|
||||
// In case tokens are not valid, it will be discovered by the first
|
||||
// api call.
|
||||
final tokenState = await ref.watch(tokensControllerProvider.future);
|
||||
if (tokenState.getAccessToken().isEmpty &&
|
||||
tokenState.getRefreshToken().isNotEmpty) {
|
||||
@@ -44,18 +35,6 @@ class AuthorizationController extends AsyncNotifier<AuthState> {
|
||||
return AuthState(isAuthorized: isAuthorized);
|
||||
}
|
||||
|
||||
AuthMode authMode = AuthMode.login;
|
||||
|
||||
void toggleAuthMode() {
|
||||
state = AsyncData(
|
||||
state.value!.copyWith(
|
||||
mode: state.value!.mode == AuthMode.login
|
||||
? AuthMode.signup
|
||||
: AuthMode.login,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> signin(SignInData form) async {
|
||||
state = const AsyncLoading();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user