-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.ts
More file actions
47 lines (39 loc) · 1.13 KB
/
Copy pathapi.ts
File metadata and controls
47 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Platform } from "react-native"
const baseUrl = Platform.OS === "android" ? "http://10.0.2.2:8089" : "http://localhost:8089"
const proxyUrl = `${baseUrl}/user/widget_urls`
interface WidgetUrlResponse {
widget_url: {
url: string
}
}
export const fetchConnectWidgetUrl = async (clientRedirectUrl: string) => {
const headers: Record<string, string> = {
"Accept-Version": "v20250224",
"Content-Type": "application/json",
}
const method = "POST"
const body = JSON.stringify({
widget_url: {
client_redirect_url: clientRedirectUrl,
is_mobile_webview: true,
ui_message_version: 4,
widget_type: "connect_widget",
data_request: { products: ["identity_verification"] },
},
})
try {
const response = await fetch(proxyUrl, {
body,
headers,
method,
})
if (!response.ok) {
throw new Error(`Failed to fetch widget URL: ${response.status} ${response.statusText}`)
}
const data: WidgetUrlResponse = await response.json()
return data.widget_url.url
} catch (error) {
console.error("Error fetching widget URL:", error)
throw error
}
}