Skip to content

Commit

Permalink
feat: add flutter app Ory Network example (ory#82)
Browse files Browse the repository at this point in the history
* feat: get current session information

* feat: create login flow

* feat: login with email and password

* feat: register with email and password

* fix: handle all errors incl deserialization error

* feat: logout & get session on home page init

* feat: show session information

* feat: add design and refactor blocs

* fix: change package and folder name

* fix: change package name

* docs: update README.md

* refactor: delete unused icon

* refactor: remove unused packages

* chore: format code

* refactor: add missing package and delete unused test

* chore: display components dynamically

* chore: clean up and format code

* fix: aal2 navigation

* chore: remove unnecessary code

* chore: fix typo and rename variables

* chore: separate exception handlings

* fix: prevent null exception
  • Loading branch information
sashatalalasha committed Oct 25, 2023
1 parent cf68bc1 commit e64fc40
Show file tree
Hide file tree
Showing 14 changed files with 399 additions and 338 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.ory_network_flutter

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
34 changes: 15 additions & 19 deletions flutter-ory-network/lib/blocs/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {

final session = await repository.getCurrentSessionInformation();

emit(AuthState.authenticated(isLoading: false, session: session));
} on CustomException catch (e) {
if (e case UnauthorizedException _) {
emit(const AuthState.unauthenticated());
} else if (e case TwoFactorAuthRequiredException _) {
emit(const AuthState.aal2Requested());
} else if (e case UnknownException _) {
emit(state.copyWith(isLoading: false, errorMessage: e.message));
} else {
emit(state.copyWith(isLoading: false));
}
emit(AuthState.authenticated(session: session));
} on UnauthorizedException catch (_) {
emit(const AuthState.unauthenticated());
} on TwoFactorAuthRequiredException catch (_) {
emit(const AuthState.aal2Requested());
} on UnknownException catch (e) {
emit(state.copyWith(isLoading: false, errorMessage: e.message));
} catch (_) {
emit(state.copyWith(isLoading: false));
}
}

Expand All @@ -73,14 +71,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
await repository.logout();

emit(const AuthState.unauthenticated());
} on CustomException catch (e) {
if (e case UnauthorizedException _) {
emit(const AuthState.unauthenticated());
} else if (e case UnknownException _) {
emit(state.copyWith(isLoading: false, errorMessage: e.message));
} else {
emit(state.copyWith(isLoading: false));
}
} on UnauthorizedException catch (_) {
emit(const AuthState.unauthenticated());
} on UnknownException catch (e) {
emit(state.copyWith(isLoading: false, errorMessage: e.message));
} catch (_) {
emit(state.copyWith(isLoading: false));
}
}
}
Loading

0 comments on commit e64fc40

Please sign in to comment.