Closed lakshyastech closed 1 year ago
Here is my code
import {Alert, SafeAreaView, StyleSheet, View} from 'react-native'; import React, {useEffect, useRef} from 'react'; import WebView from 'react-native-webview'; import CookieManager from '@react-native-cookies/cookies'; import AsyncStorage from '@react-native-async-storage/async-storage'; import colors from '../../constant/colors'; import {useRecoilState} from 'recoil'; import {islogged} from '../../../providers/recoilStore'; import { Mixpanel } from "mixpanel-react-native"; const trackAutomaticEvents = true; const mixpanel = new Mixpanel( "bcdc122a574ce8f34047d4c0fc627849", trackAutomaticEvents ); mixpanel.init();
const Login = () => { const [isadt, setisadt] = React.useState(false); const [isbdt, setisbdt] = React.useState(false); const [xzcsrftoken, setxzcsrftoken] = React.useState(false); const [loggedIn, setLoggedIn] = useRecoilState(islogged);
const INJECTED_JAVASCRIPT = (function() { window.postMessage = function(data) { window.ReactNativeWebView.postMessage(data); }; })();;
(function() { window.postMessage = function(data) { window.ReactNativeWebView.postMessage(data); }; })();
const getcookie = () => { CookieManager.get('https://www.domain.in/signin') .then(async res => { for (var key in res) { if (key.startsWith('_iamadtclient')) { AsyncStorage.setItem('iamadt', JSON.stringify(res[key])); setisadt(true); } if (key.startsWith('_iambdtclient')) { AsyncStorage.setItem('iambdt', JSON.stringify(res[key])); setisbdt(true); } if (key.startsWith('csrfc')) { AsyncStorage.setItem('xzcsrftoken', JSON.stringify(res[key])); setxzcsrftoken(res[key]); } } if (isadt && isbdt && xzcsrftoken) { setLoggedIn(true); } }) .catch(err => { Alert.alert('Error', 'Something went wrong'); }); }; const webViewRef = useRef(null); const clearCookies = document.cookie.split(';').forEach(function(c) { document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/'); }); ; const clearWebViewCookies = () => { webViewRef.current.injectJavaScript(clearCookies); };
document.cookie.split(';').forEach(function(c) { document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/'); });
useEffect(() => { mixpanel.track("sign_in_screen"); getcookie(); }, []);
return (
); }; export default Login;
+1 on this
@lakshyastech Did you find a solution to this?
Here is my code
import {Alert, SafeAreaView, StyleSheet, View} from 'react-native'; import React, {useEffect, useRef} from 'react'; import WebView from 'react-native-webview'; import CookieManager from '@react-native-cookies/cookies'; import AsyncStorage from '@react-native-async-storage/async-storage'; import colors from '../../constant/colors'; import {useRecoilState} from 'recoil'; import {islogged} from '../../../providers/recoilStore'; import { Mixpanel } from "mixpanel-react-native"; const trackAutomaticEvents = true; const mixpanel = new Mixpanel( "bcdc122a574ce8f34047d4c0fc627849", trackAutomaticEvents ); mixpanel.init();
const Login = () => { const [isadt, setisadt] = React.useState(false); const [isbdt, setisbdt] = React.useState(false); const [xzcsrftoken, setxzcsrftoken] = React.useState(false); const [loggedIn, setLoggedIn] = useRecoilState(islogged);
const INJECTED_JAVASCRIPT =
(function() { window.postMessage = function(data) { window.ReactNativeWebView.postMessage(data); }; })();
;const getcookie = () => { CookieManager.get('https://www.domain.in/signin') .then(async res => { for (var key in res) { if (key.startsWith('_iamadtclient')) { AsyncStorage.setItem('iamadt', JSON.stringify(res[key])); setisadt(true); } if (key.startsWith('_iambdtclient')) { AsyncStorage.setItem('iambdt', JSON.stringify(res[key])); setisbdt(true); } if (key.startsWith('csrfc')) { AsyncStorage.setItem('xzcsrftoken', JSON.stringify(res[key])); setxzcsrftoken(res[key]); } } if (isadt && isbdt && xzcsrftoken) { setLoggedIn(true); } }) .catch(err => { Alert.alert('Error', 'Something went wrong'); }); }; const webViewRef = useRef(null); const clearCookies =
document.cookie.split(';').forEach(function(c) { document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/'); });
; const clearWebViewCookies = () => { webViewRef.current.injectJavaScript(clearCookies); };useEffect(() => { mixpanel.track("sign_in_screen"); getcookie(); }, []);
return (
); }; export default Login;