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

Fixes for web #324

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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/',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract the link to constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is all a bit of a hack at the moment to get web working. We will need to pull this from the environment once we actually start supporting web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I promise to make this betterer in follow ups

);
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
Loading