I have used console.log at different locations in my function. My current code signs me in and redirects me to the same page. And I don't see any of the console.logs from the UseEffect() or HandleRedirect function. I don't get why the useeffect() or HandleRedirect is not being triggered after the authentication is completed.
Am I using the wrong redirect? Since I am using expo I just have my expo scheme as the name of the project. How would it be different if it was just firebase?
const AuthComponent = ({ navigation }) => {
const [response, setResponse] = useState(null); // State to hold the response
console.log("Entering auth component")
useEffect(() => {
const handleRedirect = async (event) => {
console.log("Handling redirect with URL:", event.url);
let data = Linking.parse(event.url);
console.log("Parsed redirect data:", data);
// Extract the authorization code from the URL
if (data.queryParams && data.queryParams.code) {
const code = data.queryParams.code;
console.log("Authorization code received:", code); // Log the authorization code
// Now you can exchange the authorization code for an access token
const accessToken = await exchangeCodeForToken(code);
if (accessToken) {
// With the access token, fetch the user's information from Okta
const userInfo = await getUserInfoFromOkta(accessToken);
if (userInfo) {
// Create or update the user document in Firestore with the fetched user info
await createUserDocument(userInfo);
}
}
} else {
console.log("Authorization code not found in the URL");
}
};
// Subscribe to the redirect event
const subscription = Linking.addEventListener('url', handleRedirect);
// Cleanup
return () => {
console.log("Removing URL event listener...");
subscription.remove();
};
}, []);
const signInWithOkta = async () => {
console.log("Initiating sign-in with Okta...");
let authUrl = buildAuthUrl();
console.log("Auth URL:", authUrl);
const result = await WebBrowser.openAuthSessionAsync(
authUrl,
oktaConfig.redirectUri
);
console.log("Auth session result:", result);
setResponse(result); // Store the response in state
};
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Button title="Sign in with Okta" onPress={signInWithOkta} />
</View>
);
};
The code should sign in me with okta, and extract user information based on the sign-ins.