|
| 1 | +import 'package:community_app/counter/view/counter_page.dart'; |
| 2 | +import 'package:firebase_auth/firebase_auth.dart' |
| 3 | + show ActionCodeSettings, FirebaseAuth; |
| 4 | +import 'package:firebase_ui_auth/firebase_ui_auth.dart'; |
| 5 | +import 'package:flutter/cupertino.dart'; |
| 6 | +import 'package:go_router/go_router.dart'; |
| 7 | + |
| 8 | +final providers = <AuthProvider>[ |
| 9 | + EmailAuthProvider(), |
| 10 | + EmailLinkAuthProvider( |
| 11 | + actionCodeSettings: ActionCodeSettings( |
| 12 | + url: 'http://localhost', |
| 13 | + handleCodeInApp: true, |
| 14 | + androidMinimumVersion: '1', |
| 15 | + androidPackageName: 'dev.flutterexplained.community_app.dev', |
| 16 | + iOSBundleId: 'dev.flutterexplained.community_app.dev', |
| 17 | + ), |
| 18 | + ), |
| 19 | +]; |
| 20 | + |
| 21 | +final GoRouter routerConfig = GoRouter( |
| 22 | + routes: <RouteBase>[ |
| 23 | + GoRoute( |
| 24 | + path: '/', |
| 25 | + builder: (BuildContext context, GoRouterState state) { |
| 26 | + return FirebaseAuth.instance.currentUser != null |
| 27 | + ? const CounterPage() |
| 28 | + : SignInScreen( |
| 29 | + providers: providers, |
| 30 | + actions: [ |
| 31 | + EmailLinkSignInAction((context) { |
| 32 | + context.go('/email-link-sign-in'); |
| 33 | + }) |
| 34 | + ], |
| 35 | + ); |
| 36 | + }, |
| 37 | + ), |
| 38 | + GoRoute( |
| 39 | + path: '/sign-in', |
| 40 | + builder: (BuildContext context, GoRouterState state) { |
| 41 | + return SignInScreen( |
| 42 | + providers: providers, |
| 43 | + actions: [ |
| 44 | + EmailLinkSignInAction((context) { |
| 45 | + context.go('/email-link-sign-in'); |
| 46 | + }), |
| 47 | + AuthStateChangeAction((context, state) { |
| 48 | + context.go('/profile'); |
| 49 | + }) |
| 50 | + ], |
| 51 | + ); |
| 52 | + }, |
| 53 | + ), |
| 54 | + GoRoute( |
| 55 | + path: '/email-link-sign-in', |
| 56 | + builder: (context, state) => EmailLinkSignInScreen( |
| 57 | + actions: [ |
| 58 | + AuthStateChangeAction((context, state) { |
| 59 | + context.go('/profile'); |
| 60 | + }) |
| 61 | + ], |
| 62 | + ), |
| 63 | + ), |
| 64 | + GoRoute( |
| 65 | + path: '/profile', |
| 66 | + builder: (BuildContext context, GoRouterState state) { |
| 67 | + return ProfileScreen( |
| 68 | + providers: providers, |
| 69 | + actions: [ |
| 70 | + SignedOutAction((context) { |
| 71 | + context.go('/sign-in'); |
| 72 | + }) |
| 73 | + ], |
| 74 | + ); |
| 75 | + }, |
| 76 | + ) |
| 77 | + ], |
| 78 | +); |
0 commit comments