Created
February 14, 2016 20:47
-
-
Save spencercarli/1843230c9909509c8667 to your computer and use it in GitHub Desktop.
Meteor Authentication from React Native - UI: Sign In - loggedOut.js
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
| // RNApp/app/loggedOut.js | |
| import React, { | |
| View, | |
| Text, | |
| TextInput, | |
| StyleSheet, | |
| AsyncStorage // Import AsyncStorage | |
| } from 'react-native'; | |
| import Button from './button'; | |
| import ddpClient from './ddp'; | |
| export default React.createClass({ | |
| getInitialState() { | |
| return { | |
| email: '', | |
| password: '' | |
| } | |
| }, | |
| componentDidMount() { | |
| // Grab the token from AsyncStorage - if it exists then attempt to login with it. | |
| AsyncStorage.getItem('loginToken') | |
| .then((res) => { | |
| if (res) { | |
| ddpClient.loginWithToken(res, (err, res) => { | |
| if (res) { | |
| this.props.changedSignedIn(true); | |
| } else { | |
| this.props.changedSignedIn(false); | |
| } | |
| }); | |
| } | |
| }); | |
| }, | |
| handleSignIn() { | |
| let { email, password } = this.state; | |
| ddpClient.loginWithEmail(email, password, (err, res) => { | |
| ddpClient.onAuthResponse(err, res); | |
| if (res) { | |
| this.props.changedSignedIn(true); | |
| } else { | |
| this.props.changedSignedIn(false); | |
| } | |
| }); | |
| // Clear the input values on submit | |
| this.refs.email.setNativeProps({text: ''}); | |
| this.refs.password.setNativeProps({text: ''}); | |
| }, | |
| /* | |
| * Removed from snippet for brevity | |
| */ | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment