Coder Social home page Coder Social logo

tayormi / auth_riverpod_gorouter Goto Github PK

View Code? Open in Web Editor NEW
27.0 1.0 10.0 195 KB

How to handle authentication with Riverpod and GoRouter

Kotlin 0.35% Swift 2.89% Objective-C 0.09% Dart 23.10% HTML 9.87% CMake 19.88% C++ 41.99% C 1.83%
riverpod authentication gorouter riverpod-authentication

auth_riverpod_gorouter's Introduction

Hey there

๐Ÿ”ฅ My Stats :

GitHub Streak

Tayormi's GitHub stats

๐Ÿ”ฅ About Me :

My name is Temitope and here's a little about me.

  • ๐Ÿ”ญ Iโ€™m currently building Code Clan Nigeria, a community whose goal is to turn 500+ people into developers every 3 months. www.codeclannigeria.dev
  • ๐ŸŒฑ Iโ€™m currently building a Dart Frog Enterprise API Boilerplate
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate on with community building and developer relations.
  • ๐Ÿ’ฌ Ask me about Flutter
  • ๐Ÿ“ซ How to reach me: [email protected]
  • โšก Fun fact: I love to be indoors.

My recent YouTube videos

auth_riverpod_gorouter's People

Contributors

tayormi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

auth_riverpod_gorouter's Issues

The argument type 'String? Function(GoRouterState)' can't be assigned to the parameter type 'FutureOr<String?> Function(BuildContext, GoRouterState)?'.

The argument type 'String? Function(GoRouterState)' can't be assigned to the parameter type 'FutureOr<String?> Function(BuildContext, GoRouterState)?'.

image

`final routerProvider = Provider((ref) {
final router = RouterNotifier(ref);
return GoRouter(
debugLogDiagnostics: true,
refreshListenable: router,
redirect: router._redirectLogic,
routes: router._routes);
});

class RouterNotifier extends ChangeNotifier {
final Ref _ref;

RouterNotifier(this._ref) {
ref.listen(
loginControllerProvider,
(
, __) => notifyListeners(),
);
}

String? _redirectLogic(GoRouterState state) {
final loginState = _ref.read(loginControllerProvider);

final isLoggedIn = state.location == '/login';

if (loginState is LoginStateInitial) {
  return isLoggedIn ? null : '/login';
}

if (isLoggedIn) return '/';

return null;

}

List get _routes => [
GoRoute(
name: 'login',
builder: (context, state) => const AppLoginScreen(),
path: '/login',
),
GoRoute(
name: 'home',
builder: (context, state) => const AppHomeScreen(),
path: '/',
),
GoRoute(
name: 'scan',
builder: (context, state) => const QRScanner(),
path: '/scan',
)
];
}`

Routing is not happening in my application?

Hi, i saw this project and thought it was a nice way to start my authentication flow in my application. However, the initial routing happens nicely, it identifies that the loginState is not logged in so, it gets redirected to the login page.

After that, i can't navigate to anything else but the login page tho. The debugger does say i'm navigating elsewhere:

image

My RouterProvider:
image

My login controller:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.