authGuardRedirect function

Future<String?> authGuardRedirect(
  1. dynamic context,
  2. dynamic state
)

Implementation

Future<String?> authGuardRedirect(
  BuildContext context,
  GoRouterState state,
) async {
  try {
    final acterSdk = await ActerSdk.instance;
    if (acterSdk.hasClients) {
      // we are all fine, we have a client, do go on.
      return null;
    }

    if (autoGuestLogin) {
      // if compiled with auto-guest-login, create an account
      await acterSdk.newGuestClient(setAsCurrent: true);
      return null;
    }
  } catch (e, s) {
    _log.severe('AuthGuard Fatal error', e, s);
    return state.namedLocation(
      Routes.fatalFail.name,
      queryParameters: {'error': e.toString(), 'trace': s.toString()},
    );
  }

  // no client found yet, send user to fresh login

  // next param calculation
  final next = Uri.encodeComponent(state.uri.toString());

  // ignore: deprecated_member_use
  return state.namedLocation(
    Routes.intro.name,
    queryParameters: {'next': next},
  );
}