-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: google drive integration with a sign-in flow and backup upload
- Loading branch information
1 parent
71eac99
commit 9ff7c88
Showing
12 changed files
with
241 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ yarn-error.log | |
.env | ||
google-services.json | ||
|
||
# VS Code | ||
.vscode/ |
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
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,60 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
import { GoogleSignin, GoogleSigninButton, statusCodes, User } from '@react-native-google-signin/google-signin' | ||
import { useNavigation } from '@react-navigation/core' | ||
import React, { useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { View, StyleSheet, Alert } from 'react-native' | ||
|
||
import { useAuth } from '../contexts/auth' | ||
import { useTheme } from '../contexts/theme' | ||
import { Screens } from '../types/navigators' | ||
|
||
const GoogleDriveSignIn: React.FC = () => { | ||
const [, setUserInfo] = useState<User | null>(null) | ||
const { ColorPallet } = useTheme() | ||
const navigation = useNavigation() | ||
const { t } = useTranslation() | ||
const { googleSignIn } = useAuth() | ||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: ColorPallet.brand.primaryBackground, | ||
}, | ||
}) | ||
|
||
const authenticateWithGoogle = async () => { | ||
try { | ||
await GoogleSignin.hasPlayServices() | ||
const googleUserInfo = await GoogleSignin.signIn() | ||
setUserInfo(googleUserInfo) | ||
await AsyncStorage.setItem('googleUserInfo', JSON.stringify(googleUserInfo)) | ||
googleSignIn() | ||
navigation.replace(Screens.ExportWallet, { backupType: 'google_drive' }) | ||
} catch (error: any) { | ||
if (error.code === statusCodes.SIGN_IN_CANCELLED) { | ||
Alert.alert('Sign-In Cancelled', t('GoogleDrive.SignInCancelled')) | ||
} else if (error.code === statusCodes.IN_PROGRESS) { | ||
Alert.alert('Sign-In In Progress', t('GoogleDrive.SignInProgress')) | ||
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) { | ||
Alert.alert('Play Services Not Available', t('GoogleDrive.PlayServicesNotAvailable')) | ||
} else { | ||
Alert.alert('Sign-In Error', t('GoogleDrive.SignInError')) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<GoogleSigninButton | ||
size={GoogleSigninButton.Size.Wide} | ||
color={GoogleSigninButton.Color.Dark} | ||
onPress={authenticateWithGoogle} | ||
disabled={false} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
export default GoogleDriveSignIn |
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
Oops, something went wrong.