diff --git a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift index 6d96810..9fec05d 100644 --- a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift +++ b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift @@ -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) } } diff --git a/SpotifyLyricsInMenubar/lyricJsonStruct.swift b/SpotifyLyricsInMenubar/lyricJsonStruct.swift index 3437d4c..50293ff 100644 --- a/SpotifyLyricsInMenubar/lyricJsonStruct.swift +++ b/SpotifyLyricsInMenubar/lyricJsonStruct.swift @@ -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 +} + diff --git a/SpotifyLyricsInMenubar/viewModel.swift b/SpotifyLyricsInMenubar/viewModel.swift index 8ae9d51..ee8bd5d 100644 --- a/SpotifyLyricsInMenubar/viewModel.swift +++ b/SpotifyLyricsInMenubar/viewModel.swift @@ -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") } @@ -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") } }