Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mercure connection failed with 401 while listening #1

Closed
terukaze1939 opened this issue Aug 17, 2023 · 2 comments
Closed

Mercure connection failed with 401 while listening #1

terukaze1939 opened this issue Aug 17, 2023 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@terukaze1939
Copy link

terukaze1939 commented Aug 17, 2023

I tried use

account.messages.listen((event){
setState((){
items.add(event.subject);
});
});

but while listening error occured :
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Mercure: Connection failed with 401 status code for https://mercure.mail.tm/.well-known/mercure?topic=%2Faccounts%2F64dfeeecf629(some id here)

My code
main_screen.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mailtm_client/mailtm_client.dart';
import '../providers/mailtm_client_provider.dart';
import '../widgets/main_appbar_widget.dart';
import '../widgets/main_drawer_widget.dart';
import 'package:provider/provider.dart';

class MainScreen extends StatefulWidget {
  const MainScreen({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _MainScreen createState() => _MainScreen();
}

class _MainScreen extends State<MainScreen> {
  List<String> items = [];
  late StreamSubscription streamSubscription;
  @override
  void initState() {
    super.initState();
    final mailtmProvider = Provider.of<MailTMClient>(context, listen: false);

    streamSubscription =
        mailtmProvider.userAccount!.messages.listen((event) async {
      setState(() {
        items.add(event.subject);
      });
      await streamSubscription.cancel();
    });
  }

  @override
  void dispose() {
    super.dispose();
    streamSubscription!.cancel();
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
        appBar: const MainAppBar(),
        drawer: const MainDrawerWidget(),
        body: ListView.builder(
            itemCount: items.length,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(title: Text(items[index]));
            }));
  }
}

mailtm_client_provider.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mailtm_client/mailtm_client.dart';

class MailTMClient extends ChangeNotifier {
   TMAccount? userAccount;
  Future<TMAccount> register(
      String username, String password, TMDomain domain) async {
    return await MailTm.register(
        username: username, password: password, domain: domain);
  }

  Future<TMAccount> login(String address, String password) async {
    return await MailTm.login(address: address, password: password);
  }

  Future<List<TMDomain>> getDomains() async {
    return await TMDomain.domains;
  }


}

login.dart

final TMAccount account = await mailtmProvider.login(username, password);
mailtmProvider.userAccount = account;

sorry if my explanation is not good.
Thanks.

@im-trisha
Copy link
Owner

Hi! I will look forward to this asap! I'm actually working a bit on this project after a long time, so it may take a while.

I'm sorry if i haven't noticed your issue before.

@im-trisha im-trisha self-assigned this Nov 21, 2023
@im-trisha im-trisha added bug Something isn't working good first issue Good for newcomers labels Nov 21, 2023
@im-trisha
Copy link
Owner

This should be fixed in the beta branch, i will publish this to pub.dev as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants