how does apps like oKcupid never expire the login token even after i close the app by double tap on iphone ? ( I know the technique of re-auth and make the token big, that’s not my question)
Usually we save the auth token with async but that token
gets deleted/ lost once i close the app (by double tapp n swipe up )
how come apps like okc don’t loose the token ?
any ideas on how to make it possible ?
@skevy It works normally but when user touble taps the home screen and slides the app up, i.e close the app it looses the data saved in AsyncStorage… which isnt good for the user expeirnce.
Just like other apps like okcupid and others, I Dont want the user to type in his /her credentaisl everytime they open the app after closing it.
@skevy what do you mean AsyncStorage should be persisting to a file.
Shall i create a file and write the token on it and reda it from there everytime ?
Heres my code
import { NavigationActions } from ‘react-navigation’
import axios from ‘axios’;
import { AsyncStorage } from ‘react-native’;
const ROOT = ‘http://34.128.129.12:3030’; // Its dummy ip
console.log('281- response from server = ', response);
dispatch({
type: FETCH_SUCCESS,
payload: response.data.data
});
});
}
else {
console.log(' from here , navigate the User to signin view dispatch =', dispatch);
// dispatch(NavigationActions.navigate({ routeName: 'signin' });
}
} catch (error) {
console.log('291-logging out the error in Fetch error = ',error);
}
It doesn’t seem like the code you’ve pasted here is ever setting anything in AsyncStorage, using AsynStorage.setItem. Are you doing that somewhere else?
Yes, Im sorry, here its doing the set, when user signs in.
export function signinUser({email, password}, callback ) {
console.log(email);
console.log(password);
console.log(‘9- calling the signinUser inside the actions file’);
// redux thunk gives us access to the Dispatch
return function (dispatch) {
axios.post( `${ROOT_URL}/authentication`, { email, password, strategy: 'local'})
// axios.post( `${ROOT_URL}/authentication`, { email: 'someEmail@gmail.com', password:'pass', strategy: 'local'})
.then(response => {
console.log('it worked');
console.log(response);
// dispatch({ type: AUTH_USER });
console.log('30 = response. data accessToken =', response.data.accessToken );
// localStorage.setItem('token', response.data.accessToken);
let token = response.data.accessToken;
AsyncStorage.setItem("token", token);
try { //SET TOKEN
AsyncStorage.setItem("token", token);
console.log('38 - setting token_val=', token_val);
console.log('39 calling callback ');
} catch (error) {
// Error saving data
// AUTH_ERROR
}
try { // GET TOKEN
AsyncStorage.getItem("token").then((value) => {
console.log('49- action/index.js value of token= ', token);
callback();
}).done();
if (value !== null){
// We have data!!
console.log('42 - fetching ');
console.log(value);
}
} catch (error) {
dispatch(authError('unable to fetch token'));
// Error retrieving data
} // END GET TOKEN
}).catch(err => { // error making post request to the server , POST
console.log('ERROR');
console.log(err);
dispatch(authError('Incorrect credentials'));
// //dispatch({ type: UNAUTH_USER });
});