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
deleteUserCity = async () => { | |
try { | |
await AsyncStorage.removeItem("userCity"); | |
} catch (error) { | |
console.log(`While removing userCity: ${error.message}`); | |
} | |
} |
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
getUserCity = async () => { | |
try { | |
return await AsyncStorage.getItem("userCity"); | |
catch (error) { | |
console.log(`While getting userCity: ${error.message}`); | |
return null; | |
} | |
} |
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
setUserCity = async (city) => { | |
try { | |
await AsyncStorage.setItem("userCity", city); | |
} catch (error) { | |
console.log(`While storing userCity: ${error.message}`); | |
} | |
} |
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
import React from "react"; | |
import { View, Text, Platform } from "react-native"; | |
import { Constants, Location, Permissions } from "expo"; | |
class PermissionsExample extends React.Component { | |
state = { | |
message: null, | |
location: null | |
}; | |
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
import React from "react"; | |
import { View, Text } from "react-native"; | |
import { Permissions } from "expo"; | |
class PermissionsExample extends React.Component { | |
state = { | |
message: "" | |
}; | |
async componentWillMount() { |
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
import React from "react"; | |
import { View, Text, StyleSheet, Button } from "react-native"; | |
import { Auth } from "aws-amplify"; | |
import { withAuthContext } from "../context"; | |
class Home extends React.Component { | |
handleLogout = async () => { | |
await Auth.signOut(); | |
this.props.auth.setAuthenticated(false); | |
}; |
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
import { withAuthContext } from "../context"; | |
[...] | |
export default withAuthContext(Login); |
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
handleSubmit = async () => { | |
try { | |
await Auth.signIn(this.state.email, this.state.password); | |
this.props.auth.setAuthenticated(true); | |
} catch (error) { | |
Alert.alert("Error logging in", error, { text: "OK" }); | |
} | |
}; |
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
render() { | |
const RootNavigator = createRootNavigator(this.state.isAuthenticated); | |
const AppContainer = createAppContainer(RootNavigator); | |
return ( | |
<AuthContext.Provider | |
value={{ | |
isAuthenticated: this.state.isAuthenticated, | |
setAuthenticated: this.setAuthenticated | |
}} |
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
import React from "react"; | |
export const AuthContext = React.createContext({}); | |
export const withAuthContext = ChildComponent => props => ( | |
<AuthContext.Consumer> | |
{context => <ChildComponent {...props} auth={context} />} | |
</AuthContext.Consumer> | |
); |