Skip to content

Commit

Permalink
Fix handle plaid oauth link bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-quiltt committed Nov 15, 2023
1 parent 945700a commit 359684e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ECMAScript/react-native/src/components/QuilttConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ export const QuilttConnector = ({
webViewRef.current?.injectJavaScript(script)
}, [connectionId, connectorId, session?.token])

// Convert it to a list from Quiltt Server to prevent MX changes
const allowedListUrl = ['moneydesktop.com', 'quiltt', 'cdn.plaid.com']
const shouldRender = (url: URL) => allowedListUrl.some((domain) => url.host.includes(domain))

const eventHandler = (request: ShouldStartLoadRequest) => {
const url = new URL(request.url)
if (url.host.includes('quiltt')) return true
if (shouldRender(url)) return true
if (url.protocol === 'quilttconnector:') {
handleQuilttEvent(url)
return false
}
// Plaid set oauth url by doing window.location.href = url
// This is the only way I know to handle this.
handleOAuthUrl(url.href)
handleOAuthUrl(url)
return false
}

Expand Down Expand Up @@ -101,15 +105,24 @@ export const QuilttConnector = ({
onExitSuccess?.(metadata)
break
case 'OauthRequested':
handleOAuthUrl(url.searchParams.get('oauthUrl') as string)
handleOAuthUrl(new URL(url.searchParams.get('oauthUrl') as string))
break
default:
console.log('unhandled event', url)
break
}
}

const handleOAuthUrl = (oauthUrl: string) => Linking.openURL(oauthUrl)
const handleOAuthUrl = async (oauthUrl: URL) => {
console.log(oauthUrl.href)
if (oauthUrl.protocol !== 'https:') {
console.log(`handleOAuthUrl - Skipping non https url - ${oauthUrl.href}`)
return
}
if (await Linking.canOpenURL(oauthUrl.href)) {
Linking.openURL(oauthUrl.href)
}
}

return (
<AndroidSafeAreaView>
Expand Down

0 comments on commit 359684e

Please sign in to comment.