title: Flutter web redirect user if not authentiacted
body: <p>I have a GetMaterialApp with named routes to be used in Flutter web for a dashboard project. However, I am struggling to check whether the user is authenticated and redirect the user depending on the auth state. This is my App Code:</p>
  <pre><code>GetMaterialApp(
        initialBinding: InitialBinding(),
        debugShowCheckedModeBanner: false,
        theme: CustomTheme().getLightTheme,
        themeMode: ThemeMode.light,
        title: &quot;----------&quot;,
        initialRoute: &quot;/login&quot;,
        unknownRoute: GetPage(name: &quot;/notfound&quot;, page: () =&gt; NotFoundPage()),
        getPages: [
          GetPage(name: &quot;/login&quot;, page: () =&gt; Root()),
          GetPage(name: &quot;/dashboard&quot;, page: () =&gt; Dashboard()),
        ],
      ),
  </code></pre>
  <p>I am using <code>GetX</code> to handle the authentication state. Therefore, I have access to the authentication state throughout the web app. The Root widget consists of a simple <code>Obx</code> to check the authentication state and send the user to the dashboard:</p>
  <pre><code>return Obx(() =&gt; (Get.find&lt;AuthController&gt;().loggedIn) ? Dashboard() : LoginScreen());
  </code></pre>
  <p>Sadly, that does not do the trick, as the url does not change, simply the content does. The url remains at /login.</p>
  <p>I could simply call <code>Get.toNamed(&quot;dashboard&quot;)</code> when the user is logged in, but then the dashboard page would be exposed to the url, allowing the user to reach the /dashboard url even if he is not logged in.</p>
  <p>I also do not want to create a check in every Widget or page I create, since that would be inefficient. Is there a way to check whether the user is logged in and, if not, redirect the user to the login page on every url entered?</p>
  <p>Example:</p>
  <ul>
  <li><strong><a href="http://www.adress.com/dashboard" rel="nofollow noreferrer">www.adress.com/dashboard</a></strong> would redirect to <strong><a href="http://www.adress.com/login" rel="nofollow noreferrer">www.adress.com/login</a></strong> if the user is not logged in</li>
  </ul>
  <p>Is there a way to generally check the auth-state and redirect the user accordingly using <code>GetX</code>?</p>
  <p>Side Note: I am able to get the correct authentication state <strong>every time</strong>, that is not the problem, as I use GetX.</p>
  <p><strong>Short Summary:</strong>
  Is it possible to check the auth state outside the actual widget (e.g. in the GetMaterialApp) and redirect any not-authenticated users to the login page, even if they type in the /dashboard url?</p>