@fastshot/auth 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/auth.ts +8 -2
- package/src/utils/deepLink.ts +26 -2
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -95,6 +95,7 @@ async function signInWithProvider(
|
|
|
95
95
|
options: SignInOptions
|
|
96
96
|
): Promise<void> {
|
|
97
97
|
const {
|
|
98
|
+
supabaseClient,
|
|
98
99
|
returnTo = getDefaultCallbackUrl(),
|
|
99
100
|
mode = 'browser',
|
|
100
101
|
loginHint,
|
|
@@ -116,8 +117,13 @@ async function signInWithProvider(
|
|
|
116
117
|
throw createAuthError('BROWSER_DISMISSED', 'Authentication was cancelled');
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
//
|
|
120
|
-
|
|
120
|
+
// Handle successful auth callback and restore session
|
|
121
|
+
if (result.type === 'success' && result.url) {
|
|
122
|
+
const callbackResult = await handleAuthCallback(result.url, supabaseClient);
|
|
123
|
+
if (!callbackResult.success) {
|
|
124
|
+
throw createAuthError('UNKNOWN_ERROR', callbackResult.error || 'Failed to complete authentication');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
/**
|
package/src/utils/deepLink.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
1
2
|
import { AUTH_CONFIG } from '../constants';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Get the default callback URL for OAuth
|
|
6
|
+
* Returns platform-appropriate URL:
|
|
7
|
+
* - Native (iOS/Android): fastshot://auth/callback
|
|
8
|
+
* - Web: https://current-origin/auth/callback
|
|
5
9
|
*/
|
|
6
10
|
export function getDefaultCallbackUrl(): string {
|
|
11
|
+
if (Platform.OS === 'web') {
|
|
12
|
+
// Use HTTP URL for web browsers
|
|
13
|
+
const origin = (globalThis as any).location?.origin ?? '';
|
|
14
|
+
return `${origin}/${AUTH_CONFIG.CALLBACK_PATH}`;
|
|
15
|
+
}
|
|
16
|
+
// Use deep link scheme for native
|
|
7
17
|
return `${AUTH_CONFIG.DEEP_LINK_SCHEME}://${AUTH_CONFIG.CALLBACK_PATH}`;
|
|
8
18
|
}
|
|
9
19
|
|
|
@@ -41,12 +51,26 @@ export function parseCallbackUrl(url: string): {
|
|
|
41
51
|
|
|
42
52
|
/**
|
|
43
53
|
* Check if a URL is a valid auth callback URL
|
|
54
|
+
* Supports both native deep links and web HTTP URLs
|
|
44
55
|
*/
|
|
45
56
|
export function isAuthCallbackUrl(url: string): boolean {
|
|
46
57
|
if (!url) return false;
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
// Check native deep link format: fastshot://auth/callback
|
|
60
|
+
const nativePrefix = `${AUTH_CONFIG.DEEP_LINK_SCHEME}://${AUTH_CONFIG.CALLBACK_PATH}`;
|
|
61
|
+
if (url.startsWith(nativePrefix)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check web URL format: https://*/auth/callback or http://*/auth/callback
|
|
66
|
+
try {
|
|
67
|
+
const parsedUrl = new URL(url);
|
|
68
|
+
const isHttpProtocol = parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:';
|
|
69
|
+
const hasCallbackPath = parsedUrl.pathname === `/${AUTH_CONFIG.CALLBACK_PATH}`;
|
|
70
|
+
return isHttpProtocol && hasCallbackPath;
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
/**
|