Skip to content

Commit

Permalink
Onboarding: shorten setup menubar message (so that displayed for all …
Browse files Browse the repository at this point in the history
…users), fix logout check

Only log out if accesstoken fails to decode & decoding into error works & and the code given is 401: unauthorized
This fixes onboarding messages popping up for logged in users!!!
  • Loading branch information
aviwad committed Sep 24, 2024
1 parent fd66326 commit d8dd501
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ struct SpotifyLyricsInMenubarApp: App {
return nil
} else {
// Hasn't onboarded
return "⚠️ Please Complete Onboarding Process (Click Settings)".trunc(length: truncationLength)
return "⚠️ Complete Setup (Click Settings)".trunc(length: truncationLength)
}

}
Expand Down
10 changes: 10 additions & 0 deletions SpotifyLyricsInMenubar/lyricJsonStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ struct Item: Codable {
let type: String
let id: String
}

struct ErrorWrapper: Codable {
struct Error: Codable {
let code: Int
let message: String
}

let error: Error
}

18 changes: 16 additions & 2 deletions SpotifyLyricsInMenubar/viewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ import WebKit
accessToken = try JSONDecoder().decode(accessTokenJSON.self, from: accessTokenData.0)
print("ACCESS TOKEN IS SAVED")
} catch {
UserDefaults().set(false, forKey: "hasOnboarded")
do {
let errorWrap = try JSONDecoder().decode(ErrorWrapper.self, from: accessTokenData.0)
if errorWrap.error.code == 401 {
UserDefaults().set(false, forKey: "hasOnboarded")
}
} catch {
// silently fail
}
print("json error decoding the access token, therefore bad cookie therefore un-onboard")
}

Expand Down Expand Up @@ -380,7 +387,14 @@ extension viewModel {
accessToken = try JSONDecoder().decode(accessTokenJSON.self, from: accessTokenData.0)
print("ACCESS TOKEN IS SAVED")
} catch {
UserDefaults().set(false, forKey: "hasOnboarded")
do {
let errorWrap = try JSONDecoder().decode(ErrorWrapper.self, from: accessTokenData.0)
if errorWrap.error.code == 401 {
UserDefaults().set(false, forKey: "hasOnboarded")
}
} catch {
// silently fail
}
print("json error decoding the access token, therefore bad cookie therefore un-onboard")
}
}
Expand Down

0 comments on commit d8dd501

Please sign in to comment.