@onairos/react-native 3.0.38 → 3.0.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.
@@ -71,6 +71,11 @@ export const OAuthWebView: React.FC<OAuthWebViewProps> = ({
71
71
  const handleNavigationStateChange = (navState: any) => {
72
72
  console.log(`Navigation state changed for ${platform}:`, navState.url);
73
73
 
74
+ // Don't process navigation changes while still loading the initial page
75
+ if (isLoading) {
76
+ return;
77
+ }
78
+
74
79
  // Check for error states first
75
80
  if (navState.url.includes('error=') || navState.url.includes('access_denied')) {
76
81
  console.log('OAuth error detected:', navState.url);
@@ -78,138 +83,71 @@ export const OAuthWebView: React.FC<OAuthWebViewProps> = ({
78
83
  return;
79
84
  }
80
85
 
81
- // Check for the final redirect to onairos.uk domain (this means backend callback completed)
82
- const isFinalRedirect = (
83
- navState.url.includes('onairos.uk/Home') ||
84
- navState.url.includes('onairos.uk/home') ||
85
- navState.url.includes('onairos.uk/success') ||
86
- navState.url.startsWith('https://onairos.uk/Home') ||
87
- navState.url.includes('onairos.uk') && navState.url.includes('success')
88
- );
89
-
90
- // Enhanced platform-specific success patterns
91
- const platformSuccessPatterns: Record<string, RegExp[]> = {
92
- reddit: [
93
- /reddit\.com\/api\/v1\/authorize\?done=true/,
94
- /reddit\.com\/api\/v1\/authorize\/success/,
95
- /reddit\.com.*code=/
96
- ],
97
- pinterest: [
98
- /pinterest\.com\/oauth\/success/,
99
- /pinterest\.com\/oauth\/complete/,
100
- /pinterest\.com.*code=/,
101
- /api2\.onairos\.uk\/pinterest\/callback/,
102
- /onairos\.uk.*pinterest/
103
- ],
104
- linkedin: [
105
- /linkedin\.com\/oauth\/success/,
106
- /linkedin\.com\/oauth\/complete/,
107
- /linkedin\.com\/uas\/oauth2\/authorization\/success/,
108
- /linkedin\.com.*code=/
109
- ],
110
- email: [/success/, /complete/],
111
- instagram: [
112
- /instagram\.com\/oauth\/authorize\?done=true/,
113
- /instagram\.com\/oauth\/success/,
114
- /instagram\.com.*code=/,
115
- /api2\.onairos\.uk\/instagram\/callback/,
116
- /onairos\.uk.*instagram/
117
- ],
118
- youtube: [
119
- /accounts\.google\.com\/o\/oauth2\/approval/,
120
- /youtube\.com\/oauth\/success/,
121
- /accounts\.google\.com.*code=/,
122
- /api2\.onairos\.uk\/youtube\/callback/
123
- ]
124
- };
125
-
126
- // Check for platform-specific success patterns
127
- const isPlatformSuccess = platform && platformSuccessPatterns[platform] ?
128
- platformSuccessPatterns[platform].some(pattern => pattern.test(navState.url)) :
129
- false;
130
-
131
- // Check for callback URLs that might contain the authorization code
132
- const isCallbackUrl = (
133
- navState.url.includes('/callback') ||
134
- navState.url.includes('code=') ||
135
- navState.url.includes('token=') ||
136
- navState.url.includes('access_token=') ||
137
- navState.url.includes('api2.onairos.uk') ||
138
- navState.url.includes('oauth_token=')
139
- );
140
-
141
- // Extract authorization code or token if present
142
- let authCode = null;
143
- if (isCallbackUrl) {
144
- console.log('Detected callback URL with possible code/token');
145
-
146
- // Try to extract code or token using different patterns
147
- const codeMatch = navState.url.match(/code=([^&]+)/);
148
- const tokenMatch = navState.url.match(/(?:token|access_token)=([^&]+)/);
149
- const oauthTokenMatch = navState.url.match(/oauth_token=([^&]+)/);
150
-
151
- if (codeMatch && codeMatch[1]) {
152
- authCode = decodeURIComponent(codeMatch[1]);
153
- console.log('OAuth code extracted:', authCode);
154
- } else if (tokenMatch && tokenMatch[1]) {
155
- authCode = decodeURIComponent(tokenMatch[1]);
156
- console.log('OAuth token extracted:', authCode);
157
- } else if (oauthTokenMatch && oauthTokenMatch[1]) {
158
- authCode = decodeURIComponent(oauthTokenMatch[1]);
159
- console.log('OAuth token extracted:', authCode);
160
- }
161
-
162
- // Call onSuccess with the extracted code/token
163
- if (authCode) {
164
- console.log(`Calling onSuccess for ${platform} with code:`, authCode);
86
+ // Special handling for Onairos login page (existing account check)
87
+ if (platform === 'onairos') {
88
+ // Check if user successfully logged in to Onairos
89
+ if (navState.url.includes('onairos.uk/Home') ||
90
+ navState.url.includes('onairos.uk/dashboard') ||
91
+ navState.url.includes('onairos.uk/profile')) {
92
+ console.log('Onairos login successful - existing account detected');
165
93
 
166
- // Clear timeout since OAuth completed successfully
94
+ // Clear timeout since login completed successfully
167
95
  if (timeoutRef.current) {
168
96
  clearTimeout(timeoutRef.current);
169
97
  }
170
98
 
171
- onSuccess(authCode);
172
-
173
- // Close the OAuth window after a short delay
174
- setTimeout(() => {
175
- if (onComplete) {
176
- console.log('Calling onComplete to close OAuth window');
177
- onComplete();
178
- }
179
- }, 1000);
99
+ onSuccess('onairos_login_success');
100
+ return;
101
+ }
102
+
103
+ // If still on login page, don't close
104
+ if (navState.url.includes('onairos.uk/signin') ||
105
+ navState.url.includes('onairos.uk/login')) {
106
+ console.log('Still on Onairos login page, waiting for user to complete login');
180
107
  return;
181
108
  }
182
109
  }
183
110
 
184
- // If we see the final redirect or platform-specific success, close the OAuth window
185
- if (isFinalRedirect || isPlatformSuccess) {
186
- console.log(`Detected success for ${platform}`);
111
+ // For platform OAuth flows, only close when we get the FINAL redirect from Onairos backend
112
+ // This happens AFTER the user has logged in and the backend has processed the OAuth callback
113
+ const isFinalOAuthRedirect = (
114
+ navState.url.includes('onairos.uk/Home') ||
115
+ navState.url.includes('onairos.uk/home') ||
116
+ navState.url.includes('onairos.uk/success') ||
117
+ navState.url.includes('onairos.uk/dashboard') ||
118
+ (navState.url.includes('onairos.uk') && navState.url.includes('complete'))
119
+ );
120
+
121
+ // Only close when we get the final redirect from Onairos backend
122
+ if (isFinalOAuthRedirect) {
123
+ console.log(`Final OAuth redirect detected for ${platform} - user has completed login`);
187
124
 
188
- // If we haven't already extracted a code/token, consider this a generic success
189
- if (!authCode) {
190
- console.log(`Calling onSuccess for ${platform} with generic success`);
191
- onSuccess('success');
125
+ // Clear timeout since OAuth completed successfully
126
+ if (timeoutRef.current) {
127
+ clearTimeout(timeoutRef.current);
192
128
  }
193
129
 
194
- // Close the OAuth window
195
- if (onComplete) {
196
- console.log('Calling onComplete to close OAuth window');
197
- onComplete();
198
- }
199
- }
200
-
201
- // Handle specific redirect patterns that indicate completion
202
- if (navState.url.includes('api2.onairos.uk') &&
203
- (navState.url.includes('callback') || navState.url.includes('success'))) {
204
- console.log(`Backend callback detected for ${platform}`);
205
- onSuccess('backend_callback_success');
130
+ onSuccess('oauth_complete');
206
131
 
132
+ // Close the OAuth window after a short delay
207
133
  setTimeout(() => {
208
134
  if (onComplete) {
135
+ console.log('Calling onComplete to close OAuth window');
209
136
  onComplete();
210
137
  }
211
138
  }, 1500);
139
+ return;
212
140
  }
141
+
142
+ // Log intermediate steps but don't close the WebView
143
+ if (navState.url.includes('/callback') || navState.url.includes('code=')) {
144
+ console.log(`OAuth callback detected for ${platform}, but waiting for final redirect from Onairos backend`);
145
+ // Don't close here - wait for the final redirect
146
+ return;
147
+ }
148
+
149
+ // Log other navigation for debugging
150
+ console.log(`${platform} OAuth navigation:`, navState.url);
213
151
  };
214
152
 
215
153
  const handleLoadEnd = () => {