Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost sign in #122

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:fluttercon/common/utils/misc.dart';
import 'package:fluttercon/common/utils/notification_service.dart';
import 'package:fluttercon/core/di/injectable.dart';
import 'package:fluttercon/features/about/cubit/fetch_individual_organisers_cubit.dart';
import 'package:fluttercon/features/auth/cubit/ghost_sign_in_cubit.dart';
import 'package:fluttercon/features/auth/cubit/google_sign_in_cubit.dart';
import 'package:fluttercon/features/auth/cubit/log_out_cubit.dart';
import 'package:fluttercon/features/auth/cubit/social_auth_sign_in_cubit.dart';
Expand Down Expand Up @@ -137,7 +138,15 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
),
),
BlocProvider<SendFeedbackCubit>(
create: (context) => SendFeedbackCubit(apiRepository: getIt()),
create: (context) => SendFeedbackCubit(
apiRepository: getIt(),
),
),
BlocProvider<GhostSignInCubit>(
create: (context) => GhostSignInCubit(
authRepository: getIt(),
hiveRepository: getIt(),
),
),
],
child: await builder(),
Expand Down
17 changes: 17 additions & 0 deletions lib/common/repository/auth_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:fluttercon/common/data/models/models.dart';
import 'package:fluttercon/common/utils/env/flavor_config.dart';
import 'package:fluttercon/common/utils/network.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -18,6 +19,22 @@ class AuthRepository {
],
);

Future<AuthResult> ghostSignIn() async {
try {
final response = await _networkUtil.postReq(
'${FlutterConConfig.instance!.values.baseUrl}/api/v1/login',
body: {
'email': '[email protected]',
'password': 'password',
},
);

return AuthResult.fromJson(response);
} catch (e) {
rethrow;
}
}

Future<String> signInWithGoogle() async {
try {
final googleSignInAccount = await _googleSignIn.signIn();
Expand Down
36 changes: 36 additions & 0 deletions lib/features/auth/cubit/ghost_sign_in_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:bloc/bloc.dart';
import 'package:fluttercon/common/data/models/models.dart';
import 'package:fluttercon/common/repository/auth_repository.dart';
import 'package:fluttercon/common/repository/hive_repository.dart';
import 'package:fluttercon/features/auth/cubit/social_auth_sign_in_cubit.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'ghost_sign_in_state.dart';
part 'ghost_sign_in_cubit.freezed.dart';

class GhostSignInCubit extends Cubit<GhostSignInState> {
GhostSignInCubit({
required AuthRepository authRepository,
required HiveRepository hiveRepository,
}) : super(const GhostSignInState.initial()) {
_authRepository = authRepository;
_hiveRepository = hiveRepository;
}

late AuthRepository _authRepository;
late HiveRepository _hiveRepository;

Future<void> signIn() async {
emit(const GhostSignInState.loading());
try {
final authResult = await _authRepository.ghostSignIn();
_hiveRepository
..persistToken(authResult.token)
..persistUser(authResult.user);

emit(const GhostSignInState.loaded());
} catch (e) {
emit(GhostSignInState.error(e.toString()));
}
}
}
9 changes: 9 additions & 0 deletions lib/features/auth/cubit/ghost_sign_in_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
part of 'ghost_sign_in_cubit.dart';

@freezed
class GhostSignInState with _$GhostSignInState {
const factory GhostSignInState.initial() = _Initial;
const factory GhostSignInState.loading() = _Loading;
const factory GhostSignInState.loaded() = _Loaded;
const factory GhostSignInState.error(String message) = _Error;
}
36 changes: 35 additions & 1 deletion lib/features/auth/ui/sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import 'package:auth_buttons/auth_buttons.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttercon/common/repository/firebase_repository.dart';
import 'package:fluttercon/common/utils/constants/app_assets.dart';
import 'package:fluttercon/common/utils/misc.dart';
import 'package:fluttercon/common/utils/router.dart';
import 'package:fluttercon/core/di/injectable.dart';
import 'package:fluttercon/features/auth/cubit/ghost_sign_in_cubit.dart';
import 'package:fluttercon/features/auth/cubit/google_sign_in_cubit.dart';
import 'package:fluttercon/features/auth/cubit/social_auth_sign_in_cubit.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -53,7 +56,38 @@ class SignInScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
const Image(image: AssetImage(AppAssets.flutterConKeLogo)),
GestureDetector(
onLongPress: () {
final config = getIt<FirebaseRepository>().getConfig();
if (config.isInReview &&
config.appVersion == Misc.getAppVersion()) {
MillerAdulu marked this conversation as resolved.
Show resolved Hide resolved
context.read<GhostSignInCubit>().signIn();
}
},
child: BlocConsumer<GhostSignInCubit, GhostSignInState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
loaded: () => GoRouter.of(context)
.goNamed(FlutterConRouter.decisionRoute),
error: (message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: AutoSizeText(message)),
);
},
);
},
builder: (context, state) {
return state.maybeWhen(
loading: () => Center(
child: const CircularProgressIndicator()),
orElse: () => const Image(
image: AssetImage(AppAssets.flutterConKeLogo),
),
);
},
),
),
const SizedBox(height: 64),
BlocBuilder<GoogleSignInCubit, GoogleSignInState>(
builder: (context, state) {
Expand Down
4 changes: 2 additions & 2 deletions lib/main_production.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Future<void> main() async {
});
FlutterConConfig(
values: FlutterConValues(
baseDomain: 'api.droidcon.co.ke',
urlScheme: 'https',
baseDomain: '127.0.0.1:8000',
MillerAdulu marked this conversation as resolved.
Show resolved Hide resolved
urlScheme: 'http',
hiveBox: 'fluttercon-prod',
eventSlug: 'droidconke-2022-281',
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: fluttercon
description: "A new Flutter project."
publish_to: 'none'
version: 1.15.02+11502
version: 1.16.00+11600

environment:
sdk: ">=3.5.0 <4.0.0"
Expand Down