TootSDK / TootSDK

Cross-platform Swift library for Mastodon and the fediverse
https://swiftpackageindex.com/tootsdk/tootsdk/main/documentation/tootsdk
BSD 3-Clause "New" or "Revised" License
367 stars 25 forks source link

Unable to sign in to pixelfed #127

Closed Tunous closed 1 year ago

Tunous commented 1 year ago

I'm using TootClient initializer that detects flavour by fetching instance info. Unfortunately this causes a problem with pixelfed instance I tried to connect to: https://pxlmo.com.

I'm receiving parsing issue due to missing "email" field. Looking at the implementation in TootSDK the used endpoint is /api/v1/instance which is deprecated. In code "email" is marked as required. The v2 api has completely different structure for returned object.

I don't know what the proper solution is. Move to v2 api or find which fields are optional in v1 and fix them?

Error details:
[TootSDK bug] There was an error decoding incoming data:
Value 'String' not found: Expected
String value but found null instead. codingPath: [CodingKeys(stringValue:
"email", intValue: nil)].
kkostov commented 1 year ago

The challenge is that we use the instance endpoint to retrieve information about the server (e.g. determine the flavour) which will fail for servers that haven't implemented the v2 endpoint which currently works only on flavour == mastodon && version >= 4.0.

I suggest a quick fix for now: Make everything on the Instance struct optional, except for the version field.

At a later point, we can refactor the connect method to use a new getInstanceVersion method that only gets the version to set the flavour + version of the current TootClient instance and so in the implementation of getInstanceInfo we can choose to use V1 or V2, returning an Instance in both cases.