@superfan-app/spotify-auth 0.1.33 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,15 @@ import ExpoModulesCore
2
2
  import SpotifyiOS
3
3
  import KeychainAccess
4
4
 
5
+ extension SPTSession {
6
+ convenience init?(accessToken: String, refreshToken: String, expirationDate: Date) {
7
+ self.init() // Call the parameterless initializer
8
+ setValue(accessToken, forKey: "accessToken")
9
+ setValue(refreshToken, forKey: "refreshToken")
10
+ setValue(expirationDate, forKey: "expirationDate")
11
+ }
12
+ }
13
+
5
14
  enum SpotifyAuthError: Error {
6
15
  case missingConfiguration(String)
7
16
  case invalidConfiguration(String)
@@ -92,8 +92,8 @@ public class SpotifyAuthModule: Module {
92
92
  }
93
93
 
94
94
  // Enables the module to be used as a native view.
95
- View(SpotifyAuthView.self) {
96
- Prop("name") { (_: SpotifyAuthView, prop: String) in
95
+ View(SpotifyOAuthView.self) {
96
+ Prop("name") { (_: SpotifyOAuthView, prop: String) in
97
97
  secureLog("View prop updated: \(prop)")
98
98
  }
99
99
  }
@@ -158,8 +158,7 @@ public class SpotifyAuthModule: Module {
158
158
  }
159
159
 
160
160
  func presentWebAuth(_ webAuthView: SpotifyOAuthView) {
161
- // Find the top-most view controller to present from
162
- guard let topViewController = UIApplication.shared.keyWindow?.rootViewController?.topMostViewController() else {
161
+ guard let topViewController = UIApplication.shared.currentKeyWindow?.rootViewController?.topMostViewController() else {
163
162
  onAuthorizationError("Could not present web authentication")
164
163
  return
165
164
  }
@@ -178,7 +177,7 @@ public class SpotifyAuthModule: Module {
178
177
  func dismissWebAuth() {
179
178
  // Find and dismiss the web auth view controller
180
179
  DispatchQueue.main.async {
181
- UIApplication.shared.keyWindow?.rootViewController?.topMostViewController()?.dismiss(animated: true)
180
+ UIApplication.shared.currentKeyWindow?.rootViewController?.topMostViewController().dismiss(animated: true)
182
181
  }
183
182
  }
184
183
  }
@@ -198,3 +197,18 @@ extension UIViewController {
198
197
  return self
199
198
  }
200
199
  }
200
+
201
+ // Extension to safely get key window on iOS 13+
202
+ extension UIApplication {
203
+ var currentKeyWindow: UIWindow? {
204
+ if #available(iOS 13, *) {
205
+ return self.connectedScenes
206
+ .filter { $0.activationState == .foregroundActive }
207
+ .compactMap { $0 as? UIWindowScene }
208
+ .flatMap { $0.windows }
209
+ .first(where: { $0.isKeyWindow })
210
+ } else {
211
+ return self.keyWindow
212
+ }
213
+ }
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superfan-app/spotify-auth",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Spotify OAuth module for Expo",
5
5
  "main": "src/index.ts",
6
6
  "types": "build/index.d.ts",