-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from BOBpossible/feat/#10_LoginAPI
Feat/#10 login api
- Loading branch information
Showing
27 changed files
with
479 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {useNavigation} from '@react-navigation/native'; | ||
import React, {FC, useRef} from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import {SafeAreaView} from 'react-native-safe-area-context'; | ||
import {WebView} from 'react-native-webview'; | ||
import {useRecoilState} from 'recoil'; | ||
import {AuthStackParamList} from '../nav'; | ||
import {userToken} from '../state'; | ||
|
||
//let userAgent = | ||
// 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'; | ||
const INJECTED_JAVASCRIPT = | ||
'(function() {if(window.document.getElementsByTagName("pre").length>0){window.ReactNativeWebView.postMessage((window.document.getElementsByTagName("pre")[0].innerHTML));}})();'; | ||
|
||
type SocialWebViewProps = { | ||
source: string; | ||
closeSocialModal: () => void; | ||
}; | ||
|
||
const SocialWebview: FC<SocialWebViewProps> = ({source, closeSocialModal}) => { | ||
const navigation = useNavigation(); | ||
const webviewRef = useRef<WebView | null>(null); | ||
const [token, setToken] = useRecoilState(userToken); | ||
const queryString = (rawURL: string) => { | ||
var regex = /[?&]([^=#]+)=([^&#]*)/g, | ||
params = {}, | ||
match; | ||
while ((match = regex.exec(rawURL))) { | ||
params[match[1]] = match[2]; | ||
} | ||
return params; | ||
}; | ||
const _handleMessage = async (data: any) => { | ||
const jwt = data.accessToken; | ||
try { | ||
await setToken(jwt); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
closeSocialModal(); | ||
if (data.registerStatus === 'NEW') { | ||
navigation.navigate('Register'); | ||
} else { | ||
navigation.navigate('MainNavigator'); | ||
} | ||
}; | ||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<WebView | ||
ref={webviewRef} | ||
source={{uri: source}} | ||
// userAgent={userAgent} | ||
javaScriptEnabled={true} | ||
injectedJavaScript={INJECTED_JAVASCRIPT} | ||
onMessage={_handleMessage} | ||
onNavigationStateChange={async (e) => { | ||
const result = queryString(e.url); | ||
if (e.url.includes('bobpossible.shop/auth/success')) { | ||
_handleMessage(result); | ||
webviewRef.current?.stopLoading(); | ||
} | ||
}} | ||
originWhitelist={['*']} | ||
/> | ||
</SafeAreaView> | ||
); | ||
}; | ||
export default SocialWebview; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, {FC} from 'react'; | ||
import {Modal, StyleSheet, TouchableOpacity, View} from 'react-native'; | ||
import {SafeAreaView} from 'react-native-safe-area-context'; | ||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
import SocialWebview from './SocialWebview'; | ||
|
||
type SocialWebViewModalProps = { | ||
visible: boolean; | ||
source: string; | ||
closeSocialModal: () => void; | ||
}; | ||
|
||
const SocialWebviewModal: FC<SocialWebViewModalProps> = ({visible, source, closeSocialModal}) => { | ||
return ( | ||
<Modal | ||
presentationStyle="pageSheet" | ||
animationType="slide" | ||
visible={visible} | ||
style={styles.container} | ||
> | ||
<SafeAreaView style={styles.container}> | ||
<TouchableOpacity onPress={closeSocialModal}> | ||
<View style={[styles.backButton]}> | ||
<Icon name="arrow-left" size={24} color="black" /> | ||
</View> | ||
</TouchableOpacity> | ||
<SocialWebview source={source} closeSocialModal={closeSocialModal} /> | ||
</SafeAreaView> | ||
</Modal> | ||
); | ||
}; | ||
export default SocialWebviewModal; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
backButton: { | ||
zIndex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.