diff --git a/src/components/Modal/CustomModal.tsx b/src/components/Modal/CustomModal.tsx index 8d9bf38b..74613ea4 100644 --- a/src/components/Modal/CustomModal.tsx +++ b/src/components/Modal/CustomModal.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Alert, Modal, StyleSheet, Text, Pressable, View } from 'react-native'; const message = 'Press Done button once you verify yourself from My-site'; -const CustomModal = ({ modalVisible, setModalVisible }) => { +const CustomModal = ({ modalVisible, setModalVisible, qrCodeLogin}) => { console.log('mess', message); return ( { {message} setModalVisible(!modalVisible)} + onPress={ qrCodeLogin} > Done diff --git a/src/screens/AuthScreen/AuthScreen.tsx b/src/screens/AuthScreen/AuthScreen.tsx index 82ac151a..af481689 100644 --- a/src/screens/AuthScreen/AuthScreen.tsx +++ b/src/screens/AuthScreen/AuthScreen.tsx @@ -74,6 +74,42 @@ const AuthScreen = () => { } }; + const qrCodeLogin = async () => { + const deviceId = await DeviceInfo.getUniqueId(); + + const url = `${AuthApis.QR_AUTH_API}?device_id=${deviceId}`; + // {"data": {"authorization_status": "NOT_INIT", "device_id": "389e089e7e6feb38", "device_info": "Shreya", "user_id": "T7IL7MB8YriniTw4bt39"}, "message": "Authentication document retrieved successfully."} + try { + const userInfo = await fetch(url); + const userInfoJson = await userInfo.json(); + console.log('userInfoJson', userInfoJson); + + if (!userInfoJson.token) { + const userDetailsInfo = await fetch( + `https://api.realdevsquad.com/users/userId/${scannedUserId}`, + ); + const userDetailsInfoJson = await userDetailsInfo.json(); + console.log('userDetailsInfoJson', userDetailsInfoJson); + await storeData('userData', JSON.stringify(userDetailsInfoJson.user)); + const {picture,id,username,status} = userDetailsInfoJson.user + setLoggedInUserData({ + id: id, + name: username, + profileUrl: picture.url, + status: status, + }); + } + } catch (err) { + console.error(err); + Toast.show({ + type: 'error', + text1: 'Something went wrong, please try again later', + position: 'bottom', + bottomOffset: 80, + }); + } + }; + const getAuthStatus = async () => { const deviceInfo = await DeviceInfo.getDeviceName(); const deviceId = await DeviceInfo.getUniqueId(); @@ -245,6 +281,7 @@ const AuthScreen = () => { )}