-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Implement the OAuth functionality (#24)
* initiate the routing operation * feat(auth): launch social auth * feat: complete the oauth log in flow * feat: use go_router for navigation * fix: go router doesn't work * feat: add transition to the sign up screen * feat: add the new routes * refactor: use go router instead or navigator * Update settings_section.dart
- Loading branch information
1 parent
7aaf3ae
commit 23dee9d
Showing
40 changed files
with
568 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
API_URL=https://example.com/api/v1 | ||
RECAPTCHA_SITE_KEY={reCAPTCHA_SITE_KEY} | ||
|
||
# Social auth URL | ||
GOOGLE_AUTH_URL=/auth/google | ||
GITHUB_AUTH_URL=/auth/github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
// ignore_for_file: non_constant_identifier_names | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
|
||
// ignore: non_constant_identifier_names | ||
final String BASE_URL = dotenv.env['BASE_URL']!; | ||
final String API_URL = dotenv.env['API_URL']!; | ||
final String GOOGLE_AUTH_URL = API_URL + dotenv.env['GOOGLE_AUTH_URL']!; | ||
final String GITHUB_AUTH_URL = API_URL + dotenv.env['GITHUB_AUTH_URL']!; | ||
final BASE_OPTIONS = | ||
BaseOptions(baseUrl: BASE_URL, contentType: 'application/json'); | ||
BaseOptions(baseUrl: API_URL, contentType: 'application/json'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
import 'package:telware_cross_platform/core/view/screen/splash_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view/screens/change_number_form_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view/screens/log_in_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view/screens/sign_up_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view/screens/social_auth_loading_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view/screens/verification_screen.dart'; | ||
import 'package:telware_cross_platform/features/auth/view_model/auth_view_model.dart'; | ||
import 'package:telware_cross_platform/features/home/view/screens/home_screen.dart'; | ||
import 'package:telware_cross_platform/features/home/view/screens/inbox_screen.dart'; | ||
import 'package:telware_cross_platform/features/stories/view/screens/add_my_story_screen.dart'; | ||
import 'package:telware_cross_platform/features/stories/view/screens/show_taken_story_screen.dart'; | ||
import 'package:telware_cross_platform/features/stories/view/screens/story_screen.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/block_user.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/blocked_users.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/change_number_screen.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/privacy_and_security_screen.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/profile_info_screen.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/settings_screen.dart'; | ||
import 'package:telware_cross_platform/features/user/view/screens/user_profile_screen.dart'; | ||
|
||
class Routes { | ||
static const String home = HomeScreen.route; | ||
static const String splash = SplashScreen.route; | ||
static const String logIn = LogInScreen.route; | ||
static const String signUp = SignUpScreen.route; | ||
static const String verification = VerificationScreen.route; | ||
static const String socialAuthLoading = SocialAuthLoadingScreen.route; | ||
static const String inboxScreen = InboxScreen.route; | ||
static const String addMyStory = AddMyStoryScreen.route; | ||
static const String showTakenStory = ShowTakenStoryScreen.route; | ||
static const storyScreen = StoryScreen.route; | ||
static const String settings = SettingsScreen.route; | ||
static const String changeNumber = ChangeNumberScreen.route; | ||
static const String changeNumberForm = ChangeNumberFormScreen.route; | ||
static const String profileInfo = ProfileInfoScreen.route; | ||
static const String blockUser = BlockUserScreen.route; | ||
static const String blockedUser = BlockedUsersScreen.route; | ||
static const String userProfile = UserProfileScreen.route; | ||
static const String privacySettings = PrivacySettingsScreen.route; | ||
|
||
|
||
static GoRouter appRouter(WidgetRef ref) => GoRouter( | ||
initialLocation: Routes.splash, | ||
redirect: (context, state) { | ||
final isAuthenticated = ref.read(authViewModelProvider.notifier).isAuthenticated(); | ||
if (!isAuthenticated) { | ||
if (state.fullPath != Routes.logIn && | ||
state.fullPath != Routes.signUp && | ||
state.fullPath != Routes.verification && | ||
state.fullPath != Routes.splash) { | ||
return Routes.logIn; | ||
} | ||
} | ||
return null; | ||
}, | ||
routes: [ | ||
GoRoute( | ||
path: Routes.splash, | ||
builder: (context, state) => const SplashScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.logIn, | ||
builder: (context, state) => const LogInScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.signUp, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: const SignUpScreen(), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: Routes.verification, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: const VerificationScreen(), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: '${Routes.socialAuthLoading}/:secretSessionId', | ||
builder: (context, state) { | ||
final secretSessionId = state.pathParameters['secretSessionId']!; | ||
return SocialAuthLoadingScreen(secretSessionId: secretSessionId); | ||
}, | ||
), | ||
GoRoute( | ||
path: home, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: const HomeScreen(), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: Routes.inboxScreen, | ||
builder: (context, state) => const InboxScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.addMyStory, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: const AddMyStoryScreen(), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: Routes.showTakenStory, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: ShowTakenStoryScreen(image: state.extra as File), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: Routes.storyScreen, | ||
pageBuilder: (context, state) => CustomTransitionPage( | ||
key: state.pageKey, | ||
child: StoryScreen( | ||
userId: (state.extra as Map<String, dynamic>)['userId'] as String, | ||
showSeens: (state.extra as Map<String, dynamic>)['showSeens'] as bool, | ||
), | ||
transitionsBuilder: _slideRightTransitionBuilder, | ||
), | ||
), | ||
GoRoute( | ||
path: Routes.settings, | ||
builder: (context, state) => const SettingsScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.changeNumber, | ||
builder: (context, state) => const ChangeNumberScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.changeNumberForm, | ||
builder: (context, state) => const ChangeNumberFormScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.profileInfo, | ||
builder: (context, state) => const ProfileInfoScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.blockUser, | ||
builder: (context, state) => const BlockUserScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.blockedUser, | ||
builder: (context, state) => const BlockedUsersScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.userProfile, | ||
builder: (context, state) => const UserProfileScreen(), | ||
), | ||
GoRoute( | ||
path: Routes.privacySettings, | ||
builder: (context, state) => const PrivacySettingsScreen(), | ||
), | ||
], | ||
); | ||
|
||
static Widget _slideRightTransitionBuilder( | ||
context, animation, secondaryAnimation, child) { | ||
const begin = Offset(1.0, 0.0); | ||
const end = Offset.zero; | ||
const curve = Curves.ease; | ||
|
||
final tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve)); | ||
final offsetAnimation = animation.drive(tween); | ||
|
||
return SlideTransition( | ||
position: offsetAnimation, | ||
child: child, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.