-
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.
- Loading branch information
1 parent
59bfd40
commit d5b1053
Showing
7 changed files
with
94 additions
and
15 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
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
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,45 @@ | ||
import { | ||
GoogleSignin, | ||
GoogleSigninButton, | ||
statusCodes, | ||
} from '@react-native-google-signin/google-signin'; | ||
import { useSession } from '../utils/AuthContext'; | ||
|
||
export default function GoogleAuth() { | ||
const { signInWithGoogle } = useSession(); | ||
GoogleSignin.configure({ | ||
scopes: ['https://www.googleapis.com/auth/drive.readonly'], | ||
webClientId: 'YOUR CLIENT ID FROM GOOGLE CONSOLE', | ||
}); | ||
|
||
return ( | ||
<GoogleSigninButton | ||
size={GoogleSigninButton.Size.Wide} | ||
color={GoogleSigninButton.Color.Dark} | ||
onPress={async () => { | ||
try { | ||
await GoogleSignin.hasPlayServices(); | ||
const userInfo = await GoogleSignin.signIn(); | ||
if (userInfo.idToken) { | ||
const { data, error } = await signInWithGoogle(userInfo.idToken); | ||
console.log(error, data); | ||
} else { | ||
throw new Error('no ID token present!'); | ||
} | ||
} catch (error: any) { | ||
if (error) { | ||
if (error.code === statusCodes.SIGN_IN_CANCELLED) { | ||
// user cancelled the login flow | ||
} else if (error.code === statusCodes.IN_PROGRESS) { | ||
// operation (e.g. sign in) is in progress already | ||
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) { | ||
// play services not available or outdated | ||
} else { | ||
// some other error happened | ||
} | ||
} | ||
} | ||
}} | ||
/> | ||
); | ||
} |
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