Skip to content

Instantly share code, notes, and snippets.

@spencercarli
Created February 14, 2016 20:47
Show Gist options
  • Select an option

  • Save spencercarli/1843230c9909509c8667 to your computer and use it in GitHub Desktop.

Select an option

Save spencercarli/1843230c9909509c8667 to your computer and use it in GitHub Desktop.
Meteor Authentication from React Native - UI: Sign In - loggedOut.js
// 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