Skip to content

Commit

Permalink
fix: state invalid in login-screen (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoGaonaC committed Oct 11, 2023
1 parent d3959f1 commit 4d268f8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/features/auth/presentation/providers/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,26 @@ class AuthNotifier extends StateNotifier<AuthState> {
_verifyToken(biometricToken);
return;
}

//Después intentamos con el token temporal
final tempToken =
await keyValueStorageService.getValue<String>('tempToken');

// Independientemente de si tempToken es nulo o no, ejecutamos el logout
// y ajustamos el estado.
// Ya que tempToken indica usuario temporal!
state = state.copyWith(hasBiometric: false);
logout();

// Luego, si tempToken no es nulo, puedes verificarlo o hacer
// cualquier lógica adicional si es necesario.
if (tempToken != null) {
// Se hace el logout para que se borre el token temporal
// Si desea un usuario temp volver a entrar se borra
// Si se quiere cambiar el estado entonces hacer un _verifyTokenTemp(tempToken)
logout();
//_verifyToken(tempToken);
return;
// [Lógica adicional aquí si tempToken existe, de momento no]
}

//Si llegamos hasta aquí, no hay token.
logout();
// [Posiblemente lógica adicional aquí si no hay token]
}

void _verifyToken(String token) async {
Expand Down Expand Up @@ -175,12 +182,14 @@ class AuthNotifier extends StateNotifier<AuthState> {
if (hasBiometric != true) {
await keyValueStorageService.removeKey('token');
await keyValueStorageService.removeKey('username');
await keyValueStorageService.removeKey('tempToken');
}

state = state.copyWith(
user: null,
errorMessage: errorMessage,
authStatus: AuthStatus.notAuthenticated);
user: null,
errorMessage: errorMessage,
authStatus: AuthStatus.notAuthenticated,
);
}

Future<void> biometricError([String? errorMessage]) async {
Expand Down

0 comments on commit 4d268f8

Please sign in to comment.