4
4
View ,
5
5
Text ,
6
6
Button ,
7
- Image ,
8
7
ActivityIndicator ,
9
8
StatusBar ,
10
9
} from 'react-native'
@@ -77,7 +76,7 @@ export default class AppContainer extends React.Component<{}, State> {
77
76
message : undefined ,
78
77
}
79
78
80
- modal : any
79
+ modal = React . createRef < LinkedInModal > ( )
81
80
82
81
constructor ( props : any ) {
83
82
super ( props )
@@ -86,7 +85,7 @@ export default class AppContainer extends React.Component<{}, State> {
86
85
87
86
getUser = async ( data : LinkedInToken ) => {
88
87
const { access_token, authentication_code } = data
89
- if ( access_token ) {
88
+ if ( ! authentication_code ) {
90
89
this . setState ( { refreshing : true } )
91
90
92
91
const response = await fetch ( 'https://api.linkedin.com/v2/me' , {
@@ -116,35 +115,42 @@ export default class AppContainer extends React.Component<{}, State> {
116
115
) : null
117
116
}
118
117
118
+ signOut = ( ) => {
119
+ this . setState ( { refreshing : true } )
120
+ this . modal . current
121
+ . logoutAsync ( )
122
+ . then ( ( ) =>
123
+ this . setState ( { localizedFirstName : undefined , refreshing : false } ) ,
124
+ )
125
+ }
126
+
119
127
render ( ) {
120
128
const { refreshing, localizedFirstName } = this . state
121
129
return (
122
130
< View style = { styles . container } >
123
- { ! refreshing && (
124
- < View style = { styles . linkedInContainer } >
125
- < LinkedInModal
126
- ref = { ref => {
127
- this . modal = ref
128
- } }
129
- clientID = { CLIENT_ID }
130
- clientSecret = { CLIENT_SECRET }
131
- shouldGetAccessToken = { false }
132
- redirectUri = "https://xaviercarpentier.com"
133
- onSuccess = { this . getUser }
134
- />
135
- < Button
136
- title = "Open from external"
137
- onPress = { ( ) => this . modal . open ( ) }
138
- />
139
- </ View >
140
- ) }
131
+ < View style = { styles . linkedInContainer } >
132
+ < LinkedInModal
133
+ ref = { this . modal }
134
+ clientID = { CLIENT_ID }
135
+ clientSecret = { CLIENT_SECRET }
136
+ redirectUri = "https://xaviercarpentier.com"
137
+ onSuccess = { this . getUser }
138
+ />
139
+ < Button
140
+ title = "Open from external"
141
+ onPress = { ( ) => this . modal . current . open ( ) }
142
+ />
143
+ </ View >
141
144
142
145
{ refreshing && < ActivityIndicator size = "large" /> }
143
146
144
147
{ localizedFirstName && (
145
- < View style = { styles . userContainer } >
146
- { this . renderItem ( 'Last name' , localizedFirstName ) }
147
- </ View >
148
+ < >
149
+ < View style = { styles . userContainer } >
150
+ { this . renderItem ( 'Last name' , localizedFirstName ) }
151
+ </ View >
152
+ < Button title = "Log Out" onPress = { this . signOut } />
153
+ </ >
148
154
) }
149
155
</ View >
150
156
)
0 commit comments