import React from 'react';
import { View } from 'react-native';
import { WebView } from 'react-native-webview';
import { setStorageData } from '@/storage/';

interface Props {
	navigation: any;
	route: any;
	token: String;
}
const Login = (props: Props) => {
	const loginSuccess = (data: any) => {
		console.log(data.nativeEvent.data);
		const { verifier } = JSON.parse(data.nativeEvent.data);
		setStorageData('userInfo', {
			verifier,
		});
		props.navigation.goBack();
	};
	return (
		<View style={{ flex: 1 }}>
			<WebView
				onMessage={loginSuccess}
				source={{
					uri: `https://api.twitter.com/oauth/authenticate?oauth_token=${props.route.params.token}`,
				}}
			/>
		</View>
	);
};

export default Login;
