kepelet / flo

an open source Navidrome client written in Swift
https://dub.sh/getflo
MIT License
30 stars 4 forks source link

Authentication fails when no LastFM API Key is provided #23

Open JanGross opened 2 days ago

JanGross commented 2 days ago

When logging in to an instance with no LastFM API key, the JSONDecoder function fails to create a UserAuth instance
due to a DecodingError, resulting in an unknown error being thrown on line 64.

This parameter should be optional.

Affected code: https://github.com/kepelet/flo/blob/759c8124b74b36640caed448fc9e5c5f9e22f7c3/flo/AuthViewModel.swift#L25-L41

Respective log entry:

[Request]: POST https://listen.minzkraut.com/auth/login
    [Headers]:
        Content-Type: application/json
        X-ND-Authorization: Bearer 
    [Body]:
        {"password":"[REDACTED]","username":"Minz"}
[Response]:
    [Status Code]: 200
    [Headers]:
        Content-Encoding: gzip
        Content-Length: 428
        Content-Type: application/json
        Date: Sun, 24 Nov 2024 22:43:37 GMT
        permissions-policy: autoplay=(), camera=(), microphone=(), usb=()
        referrer-policy: same-origin
        Server: openresty
        Vary: Origin, Accept-Encoding
        x-content-type-options: nosniff
        x-frame-options: DENY
        x-ratelimit-limit: 5
        x-ratelimit-remaining: 4
        x-ratelimit-reset: 1732488220
        x-served-by: listen.minzkraut.com
    [Body]:
        {"avatar":"[https://www.gravatar.com/avatar/a82123186fe3a3ce4ab3301ab254373fcfb21c07408fc99e6218d0d4fddb524a?s=50","id":"00a49b3d-d753-4181-b02f-854e853fe3c5","isAdmin":true,"name":"Minz","subsonicSalt":"db5276","subsonicToken":"08147693c3900e7349e56da02a6101b9","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG0iOnRydWUsImV4cCI6MTczNTE2NjYxNywiaWF0IjoxNzMyNDg4MjE3LCJpc3MiOiJORCIsInN1YiI6Ik1pbnoiLCJ1aWQiOiIwMGE0OWIzZC1kNzUzLTQxODEtYjAyZi04NTRlODUzZmUzYzUifQ.MjMjVKUAvwMZhOzu5Is18bSdAle-yRmODf6Pcc5W_dY","username":"Minz"}](https://www.gravatar.com/avatar/a82123186fe3a3ce4ab3301ab254373fcfb21c07408fc99e6218d0d4fddb524a?s=50%22,%22id%22:%2200a49b3d-d753-4181-b02f-854e853fe3c5%22,%22isAdmin%22:true,%22name%22:%22Minz%22,%22subsonicSalt%22:%22db5276%22,%22subsonicToken%22:%2208147693c3900e7349e56da02a6101b9%22,%22token%22:%22eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG0iOnRydWUsImV4cCI6MTczNTE2NjYxNywiaWF0IjoxNzMyNDg4MjE3LCJpc3MiOiJORCIsInN1YiI6Ik1pbnoiLCJ1aWQiOiIwMGE0OWIzZC1kNzUzLTQxODEtYjAyZi04NTRlODUzZmUzYzUifQ.MjMjVKUAvwMZhOzu5Is18bSdAle-yRmODf6Pcc5W_dY%22,%22username%22:%22Minz%22})
[Network Duration]: 0.32572197914123535s
[Serialization Duration]: 0.0006342083361232653s
[Result]: 
    failure(Alamofire.AFError.responseSerializationFailed(
        reason: Alamofire.AFError.ResponseSerializationFailureReason.decodingFailed(
        error: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "lastFMApiKey", intValue: nil),
        Swift.DecodingError.Context(
                codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "lastFMApiKey", 
                intValue: nil) ("lastFMApiKey").", 
                underlyingError: nil)
        )
    ))
)
faultables commented 2 days ago

thank for you for reporting this! i think i know where the problem is...

faultables commented 1 day ago

ok somehow i can't reproduce it (but still, i know where the problem is). can you tell me which Navidrome version you use?

JanGross commented 1 day ago

@faultables I am currently running v.0.53.3 (13af8ed4)

faultables commented 19 hours ago

thanks! gonna test it with that version