Skip to content

Commit

Permalink
Fixes for web
Browse files Browse the repository at this point in the history
For now we default to not logging in on web but also fix social media login
so we can test in logged in state.
  • Loading branch information
JElgar committed Sep 5, 2024
1 parent 727e5d4 commit 9ea665b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
18 changes: 14 additions & 4 deletions lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'dart:async';
import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'
as FacebookAuth;
import 'package:google_sign_in/google_sign_in.dart';
import 'package:logging/logging.dart';
import 'package:nowu/locator.dart';
import 'package:nowu/services/analytics.dart';
import 'package:nowu/services/storage.dart';
import 'package:nowu/utils/let.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:supabase_flutter/supabase_flutter.dart' hide User;
import 'package:supabase_flutter/supabase_flutter.dart';
Expand Down Expand Up @@ -102,12 +104,12 @@ class AuthenticationService {
.signInWithOtp(email: email, emailRedirectTo: LOGIN_REDIRECT_URL);
}

Future<OAuthLoginResult> signInWithOAuth(AuthProvider provider) async {
Future<OAuthLoginResult?> signInWithOAuth(AuthProvider provider) async {
final response = await _signInWithOAuth(provider);
return OAuthLoginResult.fromAuthResponse(response);
return response?.let(OAuthLoginResult.fromAuthResponse);
}

Future<AuthResponse> _signInWithOAuth(AuthProvider provider) {
Future<AuthResponse?> _signInWithOAuth(AuthProvider provider) {
switch (provider) {
case AuthProvider.Google:
return _signInWithGoogle();
Expand All @@ -118,9 +120,17 @@ class AuthenticationService {
}
}

Future<AuthResponse> _signInWithGoogle() async {
Future<AuthResponse?> _signInWithGoogle() async {
_logger.info('Singing in with google');

if (kIsWeb) {
await _client.auth.signInWithOAuth(
OAuthProvider.google,
redirectTo: 'http://localhost:5000/',
);
return null;
}

/// Web Client ID that you registered with Google Cloud.
const webClientId =
'938145287148-1dt6dldjl7bo0nbflfu3b95uc8lm73gl.apps.googleusercontent.com';
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/views/action_info/bloc/action_info_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:logging/logging.dart';
import 'package:nowu/services/causes_service.dart';

import 'action_info_state.dart';

class ActionInfoBloc extends Cubit<ActionInfoState> {
final CausesService _causesService;
final int _actionId;
final _logger = Logger('ActionInfoBloc');

ActionInfoBloc({required int actionId, required CausesService causesService})
: _causesService = causesService,
Expand All @@ -21,7 +23,8 @@ class ActionInfoBloc extends Cubit<ActionInfoState> {
statusUpdateState: const ActionInfoStatusUpdateState.initial(),
),
);
} catch (_) {
} catch (e) {
_logger.severe('Failed to fetch action $_actionId', e);
emit(
const ActionInfoState.fetchFailure(),
);
Expand Down
36 changes: 19 additions & 17 deletions lib/ui/views/explore/explore_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,25 @@ class ExploreTabs extends StatelessWidget {
elevation: 1,
shadowColor: CustomColors.greyLight1,
automaticallyImplyLeading: false,
flexibleSpace: Padding(
padding: EdgeInsets.symmetric(
horizontal: horizontalPadding,
vertical: 50,
),
child: BlocBuilder<ExploreFilterBloc, ExploreFilterState>(
builder: (context, state) {
return SearchBar(
leading: const Icon(Icons.search),
hintText: 'Explore now-u resources',
onChanged: (value) {
context
.read<ExploreFilterBloc>()
.updateFilter(state.copyWith(queryText: value));
},
);
},
flexibleSpace: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: horizontalPadding,
vertical: 5,
),
child: BlocBuilder<ExploreFilterBloc, ExploreFilterState>(
builder: (context, state) {
return SearchBar(
leading: const Icon(Icons.search),
hintText: 'Explore now-u resources',
onChanged: (value) {
context
.read<ExploreFilterBloc>()
.updateFilter(state.copyWith(queryText: value));
},
);
},
),
),
),
// TODO Fix the routing here!
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/views/intro/intro_route_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class IntroRouteGuard extends AutoRouteGuard {
// true to resume/continue navigation or false to abort navigation
switch (_authBloc.state) {
case _ when kIsWeb:
_logger.info('Skipping login and setup on web');
resolver.next(true);
break;
case AuthenticationStateAuthenticated(:final user)
when !user.isInitialised:
resolver.redirect(
Expand Down

0 comments on commit 9ea665b

Please sign in to comment.