How to handle Auth with WebBrowser.openAuthSessionAsync? #20981
-
I created a auth flow using I'm trying to figure out how to have access to any kind of info from the return, from cookies to query string on the URL as I have control over how my API handles the return, but I'm not being able to access any kind of info from the AuthSession. Here is the implementation: import { useEffect, useState } from "react"
import { Button, View, Text } from "react-native"
import * as WebBrowser from "expo-web-browser"
import * as Linking from "expo-linking"
export default () => {
const [result, setResult] =
useState<WebBrowser.WebBrowserAuthSessionResult | null>(null)
useEffect(() => {
console.log(result)
}, [result])
const _handlePressButtonAsync = async () => {
const baseUrl = "https://...com"
const callbackUrl = Linking.createURL("App", { scheme: "myapp" })
setResult(
await WebBrowser.openAuthSessionAsync(
`${baseUrl}/login?returnUrl=${encodeURIComponent(
`${baseUrl}/_v/login?token=...&iv=...&returnUrl=${callbackUrl}`
)}`,
callbackUrl
)
)
}
return (
<View className="items-center justify-center flex-1">
<Button title="Open Auth Session" onPress={_handlePressButtonAsync} />
{result && <Text>{JSON.stringify(result)}</Text>}
</View>
)
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Helped me through, despite not being the same problem the The final result became a little too big to paste here, but the handling ended up being relatively straightforward: useEffect(() => {
if (result?.type === "success") {
const { token, iv } = getParamsFromUrl(result.url)
const session = decrypt(token, key, iv)
console.log({ session })
}
}, [result]) |
Beta Was this translation helpful? Give feedback.
-
thank you guys this works pretty well for me too! |
Beta Was this translation helpful? Give feedback.
Helped me through, despite not being the same problem the
use the URL
quote helped me solve this by changing a bit how I thought about it!The final result became a little too big to paste here, but the handling ended up being relatively straightforward: