Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- storeToken(responseData){
- AsyncStorage.setItem('access_token', responseData, (err)=> {
- if(err){
- console.log("an error");
- throw err;
- }
- console.log("storage token was a success");
- }).catch((err)=> {
- console.log("error is: " + err);
- });
- }
- async onLoginPressed() {
- this.setState({showProgress: true})
- username = this.state.username;
- password = this.state.password;
- try {
- let response = await fetch('https://roomies-backend-prithajnath.c9users.io/get_auth_token/', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- username: username,
- password: password,
- })
- });
- let res = await response.text();
- if (response.status >= 200 && response.status < 300) {
- //Handle success
- let accessToken = res;
- console.log(accessToken);
- //On success we will store the access_token in the AsyncStorage
- this.storeToken(accessToken);
- this.redirect('Profile');
- } else {
- //Handle error
- let error = res;
- throw error;
- }
- } catch(error) {
- this.setState({error: error});
- console.log("error " + error);
- //this.setState({showProgress: false});
- }
- }
Add Comment
Please, Sign In to add comment