@superfan-app/spotify-auth 0.1.38 → 0.1.39
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.
- package/build/SpotifyAuthView.d.ts.map +1 -1
- package/build/SpotifyAuthView.js +1 -0
- package/build/SpotifyAuthView.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/ios/SpotifyAuthModule.swift +5 -2
- package/ios/SpotifyOAuthView.swift +2 -0
- package/package.json +1 -1
- package/src/SpotifyAuthView.tsx +1 -0
- package/src/index.tsx +6 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpotifyAuthView.d.ts","sourceRoot":"","sources":["../src/SpotifyAuthView.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAK3D,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAAK,EAAE,oBAAoB,GAC1B,GAAG,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"SpotifyAuthView.d.ts","sourceRoot":"","sources":["../src/SpotifyAuthView.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAK3D,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAAK,EAAE,oBAAoB,GAC1B,GAAG,CAAC,OAAO,CAGb"}
|
package/build/SpotifyAuthView.js
CHANGED
|
@@ -2,6 +2,7 @@ import { requireNativeViewManager } from "expo-modules-core";
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
const NativeView = requireNativeViewManager("SpotifyAuth");
|
|
4
4
|
export default function SpotifyAuthView(props) {
|
|
5
|
+
console.log('Registering SpotifyAuthView with props:', JSON.stringify(props));
|
|
5
6
|
return <NativeView {...props}/>;
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=SpotifyAuthView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpotifyAuthView.js","sourceRoot":"","sources":["../src/SpotifyAuthView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,UAAU,GACd,wBAAwB,CAAC,aAAa,CAAC,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAA2B;IAE3B,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeViewManager } from \"expo-modules-core\";\nimport * as React from \"react\";\nimport { ViewProps } from \"react-native\";\n\nimport { SpotifyAuthViewProps } from \"./SpotifyAuth.types\";\n\nconst NativeView: React.ComponentType<SpotifyAuthViewProps & ViewProps> =\n requireNativeViewManager(\"SpotifyAuth\");\n\nexport default function SpotifyAuthView(\n props: SpotifyAuthViewProps,\n): JSX.Element {\n return <NativeView {...props} />;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SpotifyAuthView.js","sourceRoot":"","sources":["../src/SpotifyAuthView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,UAAU,GACd,wBAAwB,CAAC,aAAa,CAAC,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAA2B;IAE3B,OAAO,CAAC,GAAG,CAAC,yCAAyC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeViewManager } from \"expo-modules-core\";\nimport * as React from \"react\";\nimport { ViewProps } from \"react-native\";\n\nimport { SpotifyAuthViewProps } from \"./SpotifyAuth.types\";\n\nconst NativeView: React.ComponentType<SpotifyAuthViewProps & ViewProps> =\n requireNativeViewManager(\"SpotifyAuth\");\n\nexport default function SpotifyAuthView(\n props: SpotifyAuthViewProps,\n): JSX.Element {\n console.log('Registering SpotifyAuthView with props:', JSON.stringify(props));\n return <NativeView {...props} />;\n}\n"]}
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAE5E,OAAO,EAEL,kBAAkB,EAElB,KAAK,eAAe,EAErB,MAAM,qBAAqB,CAAC;AAe7B;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAE5E,OAAO,EAEL,kBAAkB,EAElB,KAAK,eAAe,EAErB,MAAM,qBAAqB,CAAC;AAe7B;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAGvD;AAED,UAAU,wBAAwB;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,GACT,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CA2DxC;AAED,wBAAgB,cAAc,IAAI,kBAAkB,CAMnD"}
|
package/build/index.js
CHANGED
|
@@ -13,6 +13,7 @@ function addAuthListener(listener) {
|
|
|
13
13
|
* Prompts the user to log in to Spotify and authorize your application.
|
|
14
14
|
*/
|
|
15
15
|
export function authorize(config) {
|
|
16
|
+
console.log('[SpotifyAuth] Initiating authorization request');
|
|
16
17
|
SpotifyAuthModule.authorize(config);
|
|
17
18
|
}
|
|
18
19
|
export function SpotifyAuthProvider({ children, }) {
|
|
@@ -21,11 +22,13 @@ export function SpotifyAuthProvider({ children, }) {
|
|
|
21
22
|
const [error, setError] = useState(null);
|
|
22
23
|
const authorize = useCallback(async (config) => {
|
|
23
24
|
try {
|
|
25
|
+
console.log('[SpotifyAuth] Starting authorization process in provider');
|
|
24
26
|
setIsAuthenticating(true);
|
|
25
27
|
setError(null);
|
|
26
28
|
await SpotifyAuthModule.authorize(config);
|
|
27
29
|
}
|
|
28
30
|
catch (err) {
|
|
31
|
+
console.error('[SpotifyAuth] Authorization error:', err);
|
|
29
32
|
// Handle structured errors from the native layer
|
|
30
33
|
if (err && typeof err === 'object' && 'type' in err) {
|
|
31
34
|
setError(err);
|
|
@@ -45,10 +48,13 @@ export function SpotifyAuthProvider({ children, }) {
|
|
|
45
48
|
}
|
|
46
49
|
}, []);
|
|
47
50
|
useEffect(() => {
|
|
51
|
+
console.log('[SpotifyAuth] Setting up auth listener');
|
|
48
52
|
const subscription = addAuthListener((data) => {
|
|
53
|
+
console.log('[SpotifyAuth] Received auth event:', data.token ? 'Token received' : 'No token');
|
|
49
54
|
setToken(data.token);
|
|
50
55
|
setIsAuthenticating(false);
|
|
51
56
|
if (data.error) {
|
|
57
|
+
console.error('[SpotifyAuth] Auth event error:', data.error);
|
|
52
58
|
console.error('Spotify auth error:', data.error);
|
|
53
59
|
setError(data.error);
|
|
54
60
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAGL,0BAA0B,GAG3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAKpD,kCAAkC;AAClC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,iBAAi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AS;wBACrB,WAAW,EAAE,KAAK;qBACnB;iBACF,CAAC,CAAC;YACL,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,EACD,EAAE,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;YAC5C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAE3B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBACjD,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,CAAC,0BAA0B,CAAC,QAAQ,CAClC,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAElE;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,0BAA0B,CAAC,QAAQ,CAAC,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { EventEmitter } from \"expo-modules-core\";\nimport React, { useContext, useEffect, useState, useCallback } from \"react\";\n\nimport {\n SpotifyAuthorizationData,\n SpotifyAuthContext,\n SpotifyAuthContextInstance,\n type AuthorizeConfig,\n type SpotifyAuthError,\n} from \"./SpotifyAuth.types\";\nimport SpotifyAuthModule from \"./SpotifyAuthModule\";\n\n// First define the event name as a string literal type\ntype SpotifyAuthEventName = \"onSpotifyAuth\"; // This should match SpotifyAuthModule.AuthEventName\n\n// Create a properly typed emitter\nconst emitter = new EventEmitter(SpotifyAuthModule);\n\nfunction addAuthListener(listener: (data: SpotifyAuthorizationData) => void) {\n // Assert the event name is of the correct type\n const eventName = SpotifyAuthModule.AuthEventName as SpotifyAuthEventName;\n return emitter.addListener(eventName, listener);\n}\n\n/**\n * Prompts the user to log in to Spotify and authorize your application.\n */\nexport function authorize(config: AuthorizeConfig): void {\n SpotifyAuthModule.authorize(config);\n}\n\ninterface SpotifyAuthProviderProps {\n children: React.ReactNode;\n}\n\nexport function SpotifyAuthProvider({\n children,\n}: SpotifyAuthProviderProps): JSX.Element {\n const [token, setToken] = useState<string | null>(null);\n const [isAuthenticating, setIsAuthenticating] = useState(false);\n const [error, setError] = useState<SpotifyAuthError | null>(null);\n\n const authorize = useCallback(\n async (config: AuthorizeConfig): Promise<void> => {\n try {\n setIsAuthenticating(true);\n setError(null);\n await SpotifyAuthModule.authorize(config);\n } catch (err) {\n // Handle structured errors from the native layer\n if (err && typeof err === 'object' && 'type' in err) {\n setError(err as SpotifyAuthError);\n } else {\n // Create a generic error structure for unknown errors\n setError({\n type: 'unknown_error',\n message: err instanceof Error ? err.message : 'Authorization failed',\n details: {\n error_code: 'unknown',\n recoverable: false\n }\n });\n }\n throw err;\n }\n },\n [],\n );\n\n useEffect(() => {\n const subscription = addAuthListener((data) => {\n setToken(data.token);\n setIsAuthenticating(false);\n\n if (data.error) {\n console.error('Spotify auth error:', data.error);\n setError(data.error);\n } else {\n setError(null);\n }\n });\n return () => subscription.remove();\n }, []);\n\n return (\n <SpotifyAuthContextInstance.Provider\n value={{ accessToken: token, authorize, isAuthenticating, error }}\n >\n {children}\n </SpotifyAuthContextInstance.Provider>\n );\n}\n\nexport function useSpotifyAuth(): SpotifyAuthContext {\n const context = useContext(SpotifyAuthContextInstance);\n if (!context) {\n throw new Error(\"useSpotifyAuth must be used within a SpotifyAuthProvider\");\n }\n return context;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAGL,0BAA0B,GAG3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAKpD,kCAAkC;AAClC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAEpD,SAAS,eAAe,CAAC,QAAkD;IACzE,+CAA+C;IAC/C,MAAM,SAAS,GAAG,iBAAiB,CAAC,aAAqC,CAAC;IAC1E,OAAO,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC9D,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAMD,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,GACiB;IACzB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA0B,IAAI,CAAC,CAAC;IAElE,MAAM,SAAS,GAAG,WAAW,CAC3B,KAAK,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OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC7D,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBACjD,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,CAAC,0BAA0B,CAAC,QAAQ,CAClC,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAElE;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,0BAA0B,CAAC,QAAQ,CAAC,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { EventEmitter } from \"expo-modules-core\";\nimport React, { useContext, useEffect, useState, useCallback } from \"react\";\n\nimport {\n SpotifyAuthorizationData,\n SpotifyAuthContext,\n SpotifyAuthContextInstance,\n type AuthorizeConfig,\n type SpotifyAuthError,\n} from \"./SpotifyAuth.types\";\nimport SpotifyAuthModule from \"./SpotifyAuthModule\";\n\n// First define the event name as a string literal type\ntype SpotifyAuthEventName = \"onSpotifyAuth\"; // This should match SpotifyAuthModule.AuthEventName\n\n// Create a properly typed emitter\nconst emitter = new EventEmitter(SpotifyAuthModule);\n\nfunction addAuthListener(listener: (data: SpotifyAuthorizationData) => void) {\n // Assert the event name is of the correct type\n const eventName = SpotifyAuthModule.AuthEventName as SpotifyAuthEventName;\n return emitter.addListener(eventName, listener);\n}\n\n/**\n * Prompts the user to log in to Spotify and authorize your application.\n */\nexport function authorize(config: AuthorizeConfig): void {\n console.log('[SpotifyAuth] Initiating authorization request');\n SpotifyAuthModule.authorize(config);\n}\n\ninterface SpotifyAuthProviderProps {\n children: React.ReactNode;\n}\n\nexport function SpotifyAuthProvider({\n children,\n}: SpotifyAuthProviderProps): JSX.Element {\n const [token, setToken] = useState<string | null>(null);\n const [isAuthenticating, setIsAuthenticating] = useState(false);\n const [error, setError] = useState<SpotifyAuthError | null>(null);\n\n const authorize = useCallback(\n async (config: AuthorizeConfig): Promise<void> => {\n try {\n console.log('[SpotifyAuth] Starting authorization process in provider');\n setIsAuthenticating(true);\n setError(null);\n await SpotifyAuthModule.authorize(config);\n } catch (err) {\n console.error('[SpotifyAuth] Authorization error:', err);\n // Handle structured errors from the native layer\n if (err && typeof err === 'object' && 'type' in err) {\n setError(err as SpotifyAuthError);\n } else {\n // Create a generic error structure for unknown errors\n setError({\n type: 'unknown_error',\n message: err instanceof Error ? err.message : 'Authorization failed',\n details: {\n error_code: 'unknown',\n recoverable: false\n }\n });\n }\n throw err;\n }\n },\n [],\n );\n\n useEffect(() => {\n console.log('[SpotifyAuth] Setting up auth listener');\n const subscription = addAuthListener((data) => {\n console.log('[SpotifyAuth] Received auth event:', data.token ? 'Token received' : 'No token');\n setToken(data.token);\n setIsAuthenticating(false);\n\n if (data.error) {\n console.error('[SpotifyAuth] Auth event error:', data.error);\n console.error('Spotify auth error:', data.error);\n setError(data.error);\n } else {\n setError(null);\n }\n });\n return () => subscription.remove();\n }, []);\n\n return (\n <SpotifyAuthContextInstance.Provider\n value={{ accessToken: token, authorize, isAuthenticating, error }}\n >\n {children}\n </SpotifyAuthContextInstance.Provider>\n );\n}\n\nexport function useSpotifyAuth(): SpotifyAuthContext {\n const context = useContext(SpotifyAuthContextInstance);\n if (!context) {\n throw new Error(\"useSpotifyAuth must be used within a SpotifyAuthProvider\");\n }\n return context;\n}\n"]}
|
|
@@ -30,7 +30,7 @@ struct AuthorizeConfig: Record {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Define a private enum for mapping Spotify SDK error codes.
|
|
33
|
-
// (The raw values here are examples; adjust them to match your SDK
|
|
33
|
+
// (The raw values here are examples; adjust them to match your SDK's definitions.)
|
|
34
34
|
private enum SPTErrorCode: Int {
|
|
35
35
|
case authorizationFailed = 100
|
|
36
36
|
case renewSessionFailed = 101
|
|
@@ -66,22 +66,25 @@ public class SpotifyAuthModule: Module {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
AsyncFunction("authorize") { (config: AuthorizeConfig, promise: Promise) in
|
|
69
|
-
secureLog("Authorization requested")
|
|
69
|
+
secureLog("Authorization requested with clientId: \(config.clientId)")
|
|
70
70
|
|
|
71
71
|
// Sanitize and validate redirect URL.
|
|
72
72
|
guard let url = URL(string: config.redirectUrl),
|
|
73
73
|
url.scheme != nil,
|
|
74
74
|
url.host != nil else {
|
|
75
|
+
secureLog("Invalid redirect URL format: \(config.redirectUrl)")
|
|
75
76
|
promise.reject(SpotifyAuthError.invalidConfiguration("Invalid redirect URL format"))
|
|
76
77
|
return
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
do {
|
|
81
|
+
secureLog("Initializing auth with scopes: \(config.scopes.joined(separator: ","))")
|
|
80
82
|
try self.spotifyAuth.initAuth(config: config)
|
|
81
83
|
promise.resolve()
|
|
82
84
|
} catch {
|
|
83
85
|
// Sanitize error message.
|
|
84
86
|
let sanitizedError = self.sanitizeErrorMessage(error.localizedDescription)
|
|
87
|
+
secureLog("Auth initialization failed: \(sanitizedError)")
|
|
85
88
|
promise.reject(SpotifyAuthError.authenticationFailed(sanitizedError))
|
|
86
89
|
}
|
|
87
90
|
}
|
|
@@ -47,6 +47,7 @@ class SpotifyOAuthView: ExpoView {
|
|
|
47
47
|
// Generate a random state string for CSRF protection
|
|
48
48
|
self.state = UUID().uuidString
|
|
49
49
|
super.init(appContext: appContext)
|
|
50
|
+
secureLog("Initializing SpotifyOAuthView with state: \(String(state.prefix(8)))...")
|
|
50
51
|
setupWebView()
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -139,6 +140,7 @@ class SpotifyOAuthView: ExpoView {
|
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
private func cleanup() {
|
|
143
|
+
secureLog("Cleaning up authentication session")
|
|
142
144
|
isAuthenticating = false
|
|
143
145
|
authTimeout?.invalidate()
|
|
144
146
|
authTimeout = nil
|
package/package.json
CHANGED
package/src/SpotifyAuthView.tsx
CHANGED
|
@@ -10,5 +10,6 @@ const NativeView: React.ComponentType<SpotifyAuthViewProps & ViewProps> =
|
|
|
10
10
|
export default function SpotifyAuthView(
|
|
11
11
|
props: SpotifyAuthViewProps,
|
|
12
12
|
): JSX.Element {
|
|
13
|
+
console.log('Registering SpotifyAuthView with props:', JSON.stringify(props));
|
|
13
14
|
return <NativeView {...props} />;
|
|
14
15
|
}
|
package/src/index.tsx
CHANGED
|
@@ -26,6 +26,7 @@ function addAuthListener(listener: (data: SpotifyAuthorizationData) => void) {
|
|
|
26
26
|
* Prompts the user to log in to Spotify and authorize your application.
|
|
27
27
|
*/
|
|
28
28
|
export function authorize(config: AuthorizeConfig): void {
|
|
29
|
+
console.log('[SpotifyAuth] Initiating authorization request');
|
|
29
30
|
SpotifyAuthModule.authorize(config);
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -43,10 +44,12 @@ export function SpotifyAuthProvider({
|
|
|
43
44
|
const authorize = useCallback(
|
|
44
45
|
async (config: AuthorizeConfig): Promise<void> => {
|
|
45
46
|
try {
|
|
47
|
+
console.log('[SpotifyAuth] Starting authorization process in provider');
|
|
46
48
|
setIsAuthenticating(true);
|
|
47
49
|
setError(null);
|
|
48
50
|
await SpotifyAuthModule.authorize(config);
|
|
49
51
|
} catch (err) {
|
|
52
|
+
console.error('[SpotifyAuth] Authorization error:', err);
|
|
50
53
|
// Handle structured errors from the native layer
|
|
51
54
|
if (err && typeof err === 'object' && 'type' in err) {
|
|
52
55
|
setError(err as SpotifyAuthError);
|
|
@@ -68,11 +71,14 @@ export function SpotifyAuthProvider({
|
|
|
68
71
|
);
|
|
69
72
|
|
|
70
73
|
useEffect(() => {
|
|
74
|
+
console.log('[SpotifyAuth] Setting up auth listener');
|
|
71
75
|
const subscription = addAuthListener((data) => {
|
|
76
|
+
console.log('[SpotifyAuth] Received auth event:', data.token ? 'Token received' : 'No token');
|
|
72
77
|
setToken(data.token);
|
|
73
78
|
setIsAuthenticating(false);
|
|
74
79
|
|
|
75
80
|
if (data.error) {
|
|
81
|
+
console.error('[SpotifyAuth] Auth event error:', data.error);
|
|
76
82
|
console.error('Spotify auth error:', data.error);
|
|
77
83
|
setError(data.error);
|
|
78
84
|
} else {
|