Last active
January 21, 2021 21:04
-
-
Save AliHadiOzturk/7831dbe768bac87a6c6ded944032a4fc to your computer and use it in GitHub Desktop.
App.tsx
This file contains hidden or 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
import Amplify, { Auth, Hub } from 'aws-amplify'; | |
import React, { useEffect } from 'react'; | |
import { | |
Button, SafeAreaView, | |
StatusBar | |
} from "react-native"; | |
import awsconfig from './src/aws-exports'; | |
//Amplify tarafından oluşturulan dosyalar ile kütüphanelerin ayarlarmarlını yapıyoruz. | |
Amplify.configure(awsconfig); | |
const App = () => { | |
useEffect(() => { | |
//Component açıldığında Hub nesnesi ile kimlik doğrulama mesajlarını dinlemeye başlıyoruz. | |
//Kullanıcı giriş yaptığında ve çıkış yaptığında uygulamamızın bundan haberi olacak. | |
Hub.listen("auth", ({ payload: { event, data } }) => { | |
switch (event) { | |
case "signIn": | |
console.log(data) | |
break; | |
case "signOut": | |
console.log("Kullanıcı çıkış yaptı.") | |
break; | |
} | |
}); | |
//Giriş yapmış olan kullanıcının bilgilerini bu şekilde alabilirsiniz. | |
Auth.currentAuthenticatedUser() | |
.then(user => console.log(user)) | |
.catch(() => console.log("Not signed in")); | |
}) | |
return ( | |
<> | |
<StatusBar barStyle="dark-content" /> | |
<SafeAreaView> | |
{/* Uygulama üzerinde çıkacak buton ile Auth nesnesinin sağladığı fonksiyonu çağırarak Google ile giriş yapmak için gerekli ekranı açıyoruz. */} | |
{/*//@ts-ignore //Typescript saçma bir şekilde syntax hatası verdiği için kullandım.*/} | |
<Button onPress={(e) => Auth.federatedSignIn({ provider: 'Google' })} title="Open Google"></Button> | |
</SafeAreaView> | |
</> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment