1- import * as React from 'react' ;
1+ import React , { useState } from 'react' ;
22
33import { StyleSheet , View , Text , Button } from 'react-native' ;
44import OpenloginReactNativeSdk , {
5+ LoginResponse ,
56 LoginProvider ,
67 OpenloginNetwork ,
78} from 'openlogin-react-native-sdk' ;
89
910export default function App ( ) {
10- const [ authState , setAuthState ] = React . useState ( { } ) ;
11+ const [ result , setResult ] = useState ( '' ) ;
1112
1213 React . useEffect ( ( ) => {
13- OpenloginReactNativeSdk . addOpenloginAuthStateChangedEventListener ( state => {
14- console . log ( state ) ;
15- setAuthState ( state ) ;
16- } ) ;
1714 OpenloginReactNativeSdk . init ( {
1815 clientId :
1916 'BKJ3HmEqVmMHbFeW6E-CVPmdnVrnPhdBEI82kxgBVJGtaS4XlylvAE-1gmsv_Fa1CDj-xIhvTf3Kgd6mTn8nJtw' ,
@@ -24,35 +21,55 @@ export default function App() {
2421 . catch ( err => console . log ( `error: ${ err } ` ) ) ;
2522 } , [ ] ) ;
2623
27- // React.useEffect(() => {
28- // // OpenloginReactNativeSdk.multiply(3, 7).then(setResult);
29- // }, []);
30-
3124 return (
3225 < View style = { styles . container } >
33- < Button
34- title = "Login"
35- onPress = { ( ) =>
36- OpenloginReactNativeSdk . login ( {
37- provider : LoginProvider . GOOGLE ,
38- } )
39- . then ( result => console . log ( `success: ${ result } ` ) )
40- . catch ( err => console . log ( `error: ${ err } ` ) )
41- }
42- />
43- < Button
44- title = "Logout"
45- onPress = { ( ) =>
46- OpenloginReactNativeSdk . logout ( {
47- provider : LoginProvider . GOOGLE ,
48- } )
49- . then ( result => console . log ( `success: ${ result } ` ) )
50- . catch ( err => console . log ( `error: ${ err } ` ) )
51- }
52- />
53- < Text style = { styles . authStateText } >
54- Result: { JSON . stringify ( authState ) }
55- </ Text >
26+ < View style = { styles . box } >
27+ < Button
28+ title = "Login with Google"
29+ onPress = { ( ) =>
30+ OpenloginReactNativeSdk . login ( {
31+ provider : LoginProvider . GOOGLE ,
32+ } )
33+ . then ( result => setResult ( JSON . stringify ( result ) ) )
34+ . catch ( err => console . log ( `error: ${ err } ` ) )
35+ }
36+ />
37+ </ View >
38+ < View style = { styles . box } >
39+ < Button
40+ title = "Login with Apple"
41+ onPress = { ( ) =>
42+ OpenloginReactNativeSdk . login ( {
43+ provider : LoginProvider . APPLE ,
44+ } )
45+ . then ( result => setResult ( JSON . stringify ( result ) ) )
46+ . catch ( err => console . log ( `error: ${ err } ` ) )
47+ }
48+ />
49+ </ View >
50+ < View style = { styles . box } >
51+ < Button
52+ title = "Login with OpenLogin"
53+ onPress = { ( ) =>
54+ OpenloginReactNativeSdk . login ( { } )
55+ . then ( result => setResult ( JSON . stringify ( result ) ) )
56+ . catch ( err => console . log ( `error: ${ err } ` ) )
57+ }
58+ />
59+ </ View >
60+ < View style = { styles . box } >
61+ < Button
62+ title = "Logout"
63+ onPress = { ( ) =>
64+ OpenloginReactNativeSdk . logout ( {
65+ provider : LoginProvider . GOOGLE ,
66+ } )
67+ . then ( result => setResult ( '' ) )
68+ . catch ( err => console . log ( `error: ${ err } ` ) )
69+ }
70+ />
71+ </ View >
72+ < Text style = { styles . text } > Result: { result } </ Text >
5673 </ View >
5774 ) ;
5875}
@@ -64,11 +81,16 @@ const styles = StyleSheet.create({
6481 justifyContent : 'center' ,
6582 } ,
6683 box : {
67- width : 60 ,
68- height : 60 ,
69- marginVertical : 20 ,
84+ width : 200 ,
85+ height : 40 ,
86+ marginTop : 15 ,
7087 } ,
71- authStateText : {
72- color : 'white' ,
88+ text : {
89+ textAlign : 'center' ,
90+ fontWeight : 'bold' ,
91+ fontSize : 16 ,
92+ marginTop : 20 ,
93+ width : '100%' ,
94+ backgroundColor : 'white' ,
7395 } ,
7496} ) ;
0 commit comments