kirmanak / Mealient

An Android client for a self-hosted recipe manager Mealie.
MIT License
153 stars 5 forks source link

Login does not work on version 0.4.4 #189

Closed Slater91 closed 10 months ago

Slater91 commented 11 months ago

Hello! I recently changed my phone and I went through the process of logging in to all of my apps and services. Mealient wouldn't allow me to log in using the latest version (0.4.4), simply saying "load failed" (by the way: it should be "loading failed"!). This struck me because the app was working just fine on my old phone. I then tried deleting the app data on my old phone and login again there, and it didn't work either!

Trying to log in using version 0.4.1 from F-Droid actually worked perfectly well on both phones (a Pixel 6 Pro and a Pixel 7 Pro, both on Android 13). This seems to indicate that there is an issue with logging in on version 0.4.4.

My uneducated guess, which could therefore been wrong, is that something went wrong with https://github.com/kirmanak/Mealient/pull/175 as I am running version 1.0.0-RC1.1 which should be supported.

Let me know if you need any more information. In the meantime, thank you so much for your work!

kirmanak commented 11 months ago

Hello @Slater91 ! Thank you for reporting this. I need more information though:

  1. Is "Load failed" error shown on the "Recipes" screen, not "Login"?
  2. Were there any errors on the "Login" screen after you'd clicked "Login"?
  3. Have you tried logging in on demo.mealie.io using 0.4.4 and one of your devices?
  4. Do you have any reverse proxies in front of Mealie that might alter the response? For example, those that compress the response.
  5. What is the exact build number reported in "Site settings" of your mealie? https://your-mealie/admin/site-settings

I was not able to reproduce the issue with either demo.mealie.io or my personal Mealie :-(

Slater91 commented 11 months ago
  1. Whenever I input the URL, it automatically switches to the "Recipes" screen and displays the message, which keeps on showing after logging in.
  2. No, nothing.
  3. "Load error: unauthorized."
  4. Yes, I have a NGINX Proxy Manager container as reverse proxy, but even using the direct IP doesn't work.
  5. It is not reported.

The funny thing is that version 0.4.4 works perfectly well if I login using version 0.4.1, so something has changed between these two in how login is managed.

kirmanak commented 11 months ago

I believe, authentication works fine but Mealient is unable to fetch the list of recipes. I suspect that it doesn't matter if you update from 0.4.1 or do a clean install of 0.4.4, it fails either way. The difference is that when you update from 0.4.1, Mealient shows you a cached list of recipes, but it is still unable to fetch the latest data.

Would you be comfortable sharing the logs with me?

I made an effort to replace Mealie URL with "" and credentials with "" and "". However, the recipes, shopping lists, and API tokens will still be logged. The app allows you to send file to yourself instead. That way you can view and remove any data you want before sharing it. You can also inspect the logs yourself and share only the part that you think explains the issue.

If that is okay with you, please install the attached build, reproduce the issue, click "Email logs" button in the menu, and select your email app. logs-build.zip

Slater91 commented 11 months ago

That is not actually the case. My comment about updating stems from the fact that if I log in on v0.4.1 and then update to v0.4.4 everything works perfectly. I tested it multiple times. In fact, I did the whole process again (remove the app, install v0.4.1, log in, update to 0.4.4) earlier to write the previous comment, and I have just now tried creating a new recipe on the Web interface: it shows up correctly on the app (updated to v0.4.4). This means that v0.4.4 works as expected and fetches new recipes; the issue really only is with logging in.

No problem in sending the logs, I will email them to you later.

FeralFlora commented 11 months ago

I cannot login on any version later than 0.4.1. All the later versions ask "Is it Mealie?". I'm still stuck on Mealie 0.5.6, btw.

kirmanak commented 11 months ago

@FeralFlora That is expected. v0.5.6 is almost two years older than the most recent version and has a different API. Since I don't expect many people to use such an old version, I don't see any value in supporting two different APIs. Please, update your Mealie as described here.

@Slater91 That is an interesting observation, thank you! Let me know if you have any issues collecting the logs, looking forward to investigate what went wrong.

FeralFlora commented 11 months ago

@FeralFlora That is expected. v0.5.6 is almost two years older than the most recent version and has a different API. Since I don't expect many people to use such an old version, I don't see any value in supporting two different APIs. Please, update your Mealie as described here.

Yeah, I know, and I would if I could. However, I'm hosting it through the PikaPods service, and they only upgrade to "stable" releases.

I've tried to argue that Mealie 0.5.6 that is outdated and unsupported, and that they should upgrade now that release candidate versions of 1.0.0 have been released, alas to no avail so far.

In October, I wrote this to the developer:

I was hoping that I could convince you to upgrade the Mealie version from 0.5.6 (pre-beta) to the new release candidate version 1.0.0-RC1.1 (released 4 days ago), which should be stable enough for production.

The old version has poor support, and is very far behind version 1.0.0 feature and stability wise

This is the response I got:

We generally only put stable releases out to customer pods. While I understand that you want to try the latest test version, PikaPods prioritizes stability. Once a new stable release is out, we'll also test or add a migration process that will run in the background. - @pikapods

FeralFlora commented 11 months ago

@kirmanak Was support for the old API deprecated after 0.4.1, then?

kirmanak commented 11 months ago

@FeralFlora yes, 0.4.1 should be the last one to support the two versions of API

kirmanak commented 10 months ago

@Slater91 I have received the logs, thank you! In those logs I found these lines:

2023-12-26T09:34:40.958491 V OkHttp: <-- 500 https://<host>/api/recipes?page=1&perPage=150 (58ms)
2023-12-26T09:34:40.958687 V OkHttp: server: openresty
2023-12-26T09:34:40.95871 V OkHttp: date: Tue, 26 Dec 2023 08:34:40 GMT
2023-12-26T09:34:40.958722 V OkHttp: content-type: text/plain; charset=utf-8
2023-12-26T09:34:40.958746 V OkHttp: content-length: 21
2023-12-26T09:34:40.959015 V OkHttp: 
2023-12-26T09:34:40.959056 V OkHttp: Internal Server Error
2023-12-26T09:34:40.959156 V OkHttp: <-- END HTTP (21-byte body)

For some unknown reason your server responds with "Internal Server Error" message. Please, check Mealie logs for any errors.

Mealient doesn't do anything unusual, here is the request:

2023-12-26T09:34:40.899427 V OkHttp: --> GET https://<host>/api/recipes?page=1&perPage=150 h2
2023-12-26T09:34:40.89949 V OkHttp: Accept-Encoding: gzip,deflate,identity
2023-12-26T09:34:40.899502 V OkHttp: Accept: application/json
2023-12-26T09:34:40.899509 V OkHttp: Accept-Charset: UTF-8
2023-12-26T09:34:40.899515 V OkHttp: User-Agent: Ktor client
2023-12-26T09:34:40.899522 V OkHttp: Host: <host>
2023-12-26T09:34:40.899531 V OkHttp: Connection: Keep-Alive
2023-12-26T09:34:40.899538 V OkHttp: --> END GET

Let me know if you find any errors in the server logs, it might be an issue in Mealie that should be reported to them.

Slater91 commented 10 months ago

Nothing appears in Mealie's logs. Here is the bit where I have just tried logging in:

          INFO: 26-Dec-23 10:11:21  password reset tokens purged
          INFO: 26-Dec-23 10:11:21  finished purging group data exports. 0 exports removed from group data

On the other hand, I have just found an additional bit which seems to point to the issue being in Mealient's code. If I close the app and re-open it, it loads the recipes normally. Call me stupid for not noticing this before. It looks like the process to load the recipes right after login fails due to some error in Mealient, but closing and re-opening the application apparently makes things work - possibly due to a different process taking place?

kirmanak commented 10 months ago

@Slater91 I honestly don't see how internal server error might be fixed that way... Can you kindly record the Mealient logs of that scenario? I.e. install the app, configure connection and sign-in, then restart the app once you see the error, and send the logs when you see the recipes. Thanks a lot for your help in debugging this!

kirmanak commented 10 months ago

I have finally figured it out thanks to all the information and logs provided by @Slater91. Indeed, it was introduced in #175 as this PR switches the network layer to use Ktor instead of Retrofit. Turns out, this issue is listed in their issue tracker https://youtrack.jetbrains.com/issue/KTOR-4759/Auth-BearerAuthProvider-caches-result-of-loadToken-until-process-death . The fact that this particular Mealie instance returns 500 instead of 401 makes things much worse as even refreshToken function is not called.

I will go with the solution described here https://youtrack.jetbrains.com/issue/KTOR-4759/Auth-BearerAuthProvider-caches-result-of-loadToken-until-process-death#focus=Comments-27-6422735.0-0 as this workaround is already implemented for sign-out scenario.

kirmanak commented 10 months ago

Should be fixed in v0.4.5