metabolist / metatext

A free, open-source iOS Mastodon client.
https://metabolist.org/metatext
GNU General Public License v3.0
727 stars 102 forks source link

Editing profile and account settings if WEB_DOMAIN and LOCAL_DOMAIN differ #217

Open TiMESPLiNTER opened 2 years ago

TiMESPLiNTER commented 2 years ago

Describe the bug It’s not possible to edit profile and account settings in the app if the instance has set a different WEB_DOMAIN than the LOCAL_DOMAIN. For example:

WEB_DOMAIN=mastodon.example.com LOCAL_DOMAIN=example.com.

More details about how Mastodon works in this case: https://github.com/felx/mastodon-documentation/blob/master/Running-Mastodon/Serving_a_different_domain.md

To Reproduce Steps to reproduce the behavior:

  1. Configure instance as described above
  2. Log into an account of this instance
  3. Click on your Avatar in the top left
  4. Click on ‚Edit profile‘ or ,Account settings‘
  5. You get a 404 because the path for these two menu items get constructed in the wrong way (i.e. https://example.com/… instead of https://mastodon.example.com/…) if you have set a different WEB_DOMAIN than the LOCAL_DOMAIN for the Mastodon instance.

Expected behavior The correct pages should open up to edit the settings

TiMESPLiNTER commented 1 year ago

I digged a bit into the code and it seems that the methods NavigationViewModel.accountSettingsURL and NavigationViewModel.editProfileURL should use the URL from the secrets, which is the correct one (it's also the URI the MastodonAPIClient class uses):

let secrets = Secrets(identityId: identityContext.identity.id, keychain: environment.keychain)

defer { secrets.deleteAllItems() }

do {
    let instanceURI = try secrets.getInstanceURL();

    if instanceURI.hasPrefix("https://") {
        return URL(string: "\(instanceURI)/auth/edit")
    } else {
        return URL(string: "https://\(instanceURI)/auth/edit")
    }
} catch {}