aluedtke7 / shoppinglist

A shoppinglist app made with Flutter and PocketBase
MIT License
18 stars 4 forks source link

Not really a bug, but more a question #1

Closed PJPAC closed 11 months ago

PJPAC commented 11 months ago

Hi, I'm a flutter/dart newbie and last week I found out about your shoppinglist app on flutterawesome.com. I thought it was a fun and useful project so that on Monday I embarked into trying to understand your code and the architecture you've chosen. I unzipped the file, installed it, and started to check it with AndroidStudio as an IDE connected to my mobile phone. I have installed pocketbase, which I have also been discovering... then for the past day and half I've been stuck at the login page and I was wondering if you would have any idea of what I did wrong.

From pocketbase, I've created a couple of users and collection named shoppinglist which I fed with a few articles. Navigating with pocketbase, these are associated with the following url : http://127.0.0.1:8090/_/#/collections?collectionId=_pb_users_auth_&filter=&sort=-created and http://127.0.0.1:8090/_/#/collections?collectionId=3mv593ieqawcouz&filter=&sort=-created.

However, when, from the IDE, I run the app on my phone I cannot pass the login page. The error I get is ClientException: {url: http://localhost:8090/api/collections/users/auth-with-password, isAbort: true, statusCode: 0, response: {}, originalError: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 41496, uri=http://localhost:8090/api/collections/users/auth-with-password}

The port number varies, but the rest of the error message is unchanged. I have not found error number list on Pocketbase so that I cannot fully identify errno = 111, while "Connection refused" is rather broad. The app login requests do reach pocket_base_prov.dart/login method but final authData = await _pb.collection('users').authWithPassword(email, password); does not seem to fill the variable, if I trust a set of debugPrint(); positioned before and after the corresponding line.

I guess I did not set the communication between pocketbase and the app properly. At the same time installing pocketbase is rather straightforward as there is no external host, so that I'm a bit stuck, so that I've thought about reaching to you in case you would have any suggestion.

Many Thanks & Best Wishes PAscal

aluedtke7 commented 11 months ago

Hi Pascal,

I think the problem is the following: When you run the app on your phone, the app tries to connect to localhost:8090. But this is the phone localhost and not the localhost of the pc where PocketBase ist running. You have to compile the phone app with the correct ip address of your pc. This is most probably something like 192.168.0.xxx. Please check this to be sure about the address.

So your build command should look like this: flutter build apk --dart-define=SHOPPINGLIST_HOST=http://192.168.0.xxx:8090

If you look at the README.md, I made a paragraph about this. Search for Important.

You can also try to run the app on your pc. This should work on Windows, Linux and macOS. This might be easier for the start. There is also a paragraph about run configurations in VSCode to handle this.

Another idea is to run PocketBase on fly.io as I do it. There is a detailed description how to do this in the PocketBase repo here on github. This works really good and costs nothing. I use it for several months now and can't complain. When you run PocketBase outside of your pc on a real domain (public ip address), you don't have these problems and the url for your PocketBase server is always the same.

Hope this helps

aluedtke7 commented 11 months ago

I updated the README.md. I hope this topic is now better described.

PJPAC commented 11 months ago

Hi, Thanks a lot for your feedback and apologies for my late reply. I've tried first to change localhost for the computer IP address. It showed positive signs with the error message not popping up immediately, the circular progress bar kept rotating but eventually a "Connection timed out" message popped up ClientException: {url: http://192.168.x_hiddennumbers_x:8090/api/collections/users/auth-with-password, isAbort: true, statusCode: 0, response: {}, originalError: ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110), address = 192.168.xxxx, port = 46620, uri=http://192.168.xxxx:8090/api/collections/users/auth-with-password}.

Next, I've set back the initial settings (i.e. localhost), then checked with a virtual device (Pixel & API 30), which led back to the initial connection refused error message. ClientException: {url: http://localhost:8090/api/collections/users/auth-with-password, isAbort: true, statusCode: 0, response: {}, originalError: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 49920, uri=http://localhost:8090/api/collections/users/auth-with-password}

I have then engaged in setting up PocketBase on Fly.io. It was the first time I was doing so and the first time I was using Docker, so that it was not that straightforward. I've managed eventually to set up the admin email parameters, recreated 3 users and a couple of products. Yet, I cannot connect with any of these users so that I kept on spreading debugPrints in the code to try to follow what it does and to spot where it goes wrong. Typing a login/pwd set, the run console displays I/flutter (17099): !!!!!! _submit !!!!!! I/flutter (17099): !!! login_page _isLoading: true I/flutter (17099): !!! login_page _email: test0@test.com I/flutter (17099): !!! login_page _password: Test0000 I/flutter (17099): !!!!!!!!!!!!! You're in Login !!!!!!!!!!!!! I/flutter (17099): !!!!!! authData: {"token":"","record":null,"meta":{}} !!!!!! I/flutter (26453): !!! _userName : !!! I/flutter (26453): !!! _pb.authStore.token : !!! E/flutter (17099): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null. E/flutter (17099): Receiver: null E/flutter (17099): Tried calling: id E/flutter (17099): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) E/flutter (17099): #1 PocketBaseProvider.login (package:shoppinglist/provider/pocket_base_prov.dart:56:71) E/flutter (17099): E/flutter (17099): #2 _LoginCardState._submit (package:shoppinglist/view/login_page.dart:101:9) E/flutter (17099):

1 corresponds to "prefs.setString(PrefKeys.accessModelPrefsKey, _pb.authStore.model.id ?? '');"

2 corresponds to "await Provider.of(context, listen: false).login(_email, _password);"

However, I'm unclear how to check #0 and the "Unhandled Exception" associated information.

In parallel, PocketBased seems to be properly pinged... I/flutter (10034): !!!!!! ensureKeepAlive.timer: Instance of '_Timer' !!!!!! I/flutter (10034): !!!!!! doHealthCheck.value: {"code":200,"message":"API is healthy.","data":{"canBackup":true}} !!!!!! with the expect 200 code being received.

The circular bar keeps running ad-vitam-eternam, without any error message popping up. I face the same situation if I fill up the login field with a gmail address. When selecting the "forgot pwd" icon, I see the “an email was sent message” popup. Eventually I get a PocketBase email, but ticking the verify button, opens a webpage with the following message “Invalid or expired verification token.”. If it can bring some insight, the url is https://sharedshoppinglist.fly.dev/_/#/auth/confirm-verification/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJfX3BiX3Rlc3RfY29sbGVjdGlvbl9pZF9fIiwiZW1haWwiOiJwYXNjYWwuanAuYW5kcmVAZ21haWwuY29tIiwiZXhwIjoxNjk5MjY1Njk4LCJpZCI6Il9fcGJfdGVzdF9pZF9fIiwidHlwZSI6ImF1dGhSZWNvcmQifQ.B4lKwqGjlvFYYDqr6r9G4MKeXXm94-RddYzi8sA61yE.

As a result, and sadly enough, I still cannot rule out a setting issue with PocketBase/Dockers/fly.io trio... even though ping is OK... and I'm unclear about what could be my next attempt to fix the issue(s).

Best Wishes PAscal

aluedtke7 commented 11 months ago

Hi Pascal,

maybe you should make a step back and try first with a native app for your dev pc. A mobile device makes things more complicated as you found out by yourself. So, if you are i.e. using Windows try this:

Does this work?

aluedtke7 commented 11 months ago

By the way: if you want to use the I forgot my password, please send me a new one feature from PocketBase, you have to configure a SMTP Server inside of PocketBase. You need an account for this SMTP server to send e-mails! Otherwise you will never get an e-mail from your PocketBase server.

Please check the PocketBase documentation for this.

PJPAC commented 11 months ago

Hi, Many thanks for your suggestion and patience. Trying to run shoppinglist as a native app for my pc Windows (Desktop), eventually worked. Out of the 3 users I had previously created, one systematically returned a error message but it was clear the user was not recognised, I still don't know why. In contrast, the 2 other users worked fine.

It motivated me to try running the app with a virtual device and while using my IP address. It returned "ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110)".

Then, I realized that I had typed 'http://xxxx.fly.dev' which I corrected with 'https://xxxx.fly.dev'. Tried with my phone and previously created users, only to face 'Failed to authenticate'. Somehow, creating a new user made it work with my phone, Windows (Desktop), and a virtual device. I'm unclear why Pocketbase does not recognized the old users but overall shoppinglist app seems to work as it should, which is what matters.

Many thanks again for your suggestions and patience. I'll definitely remember to start testing as a native app before moving to a phone.

Best Wishes PAscal