Keep logging in

Solved!
Posted in General by Issac Chua Sat Jun 04 2016 06:12:41 GMT+0000 (UTC)·9·Viewed 1,218 times

Hello everyone, I was wondering how can I keep myself logging in? For example, when I open up the app, instead of requiring me to login everytime, is there any chance to store my credentials on the app so that the next time I open up the app, I will be automatically login and use the app. This option could simply return a boolean value to check whether the user is already login or not, that way we can do the login we want if the result turns false, or continue if true.
Bradley Serbus
June 6, 2016

Hi Issac,

If you are using the SDKs, they should take care of keeping the user logged in. Can you tell me what platform you are on? If you aren't using the SDKs, I recommend doing so, for just this situation.

Thanks,
Brad


Bradley Serbus marked this as solved
Issac Chua
June 6, 2016

Well, when the app is destroyed, apparently the user needs to relogin again. I guess what other apps do is that they save the user credential internally in the app and if the app is destroyed for some reasons, they can use the information stored to log user in again.

I actually have frustration while using Buddy SDK. First of all, I keep getting AuthUserAccessTokenRequired error while performing operation like creating new user for example. About 3 out of 5 times I get SocketTimeOutException - read time out. I don't know what is better way of preventing this error though, any idea?

Bradley Serbus
June 6, 2016

Hi Issac,

I'm sorry you've been frustrated using the SDKs. Most apps use the SDKs, which should be handling saving of login state for you. I'm not sure why you are getting the AuthUserAccessTokenRequired error, since creating a user should log in the user automatically. I can provide better guidance if you let me know what platform you're developing on.

Thanks,
Brad

Bradley Serbus
June 6, 2016

Hi Issac,
I looked through our server data, and it looks like you are developing for Android. I recommend using the SDK's createUser, loginUser, and logoutUser methods, vs. making the REST calls yourself, if you are doing the latter. Only the former calls handle the authentication tokens for you. As for your SocketTimeOutExceptions, I recommend implementing the connection callback as detailed in the "Handling Connectivity" section in the SDK documentation at http://docs.buddy.com/docs/android-sdk. That will help with connection issues.
Thanks,
Brad

Issac Chua
June 7, 2016

Hi Bradley, thanks for your reply. Of course, I am using Android SDK to perform createUser and etc. I have been following thoroughly and step by step making sure that I don't miss anything. For operation such as Buddy.get(...), Buddy.createUser(...) ... , the only thing that we need to have is the Buddy.init(...) is that right? So far I have been testing a lot, and I think I will have to accept the occurrence of SocketTimeoutException.

In your opinion, what is the best way to tackle the timed out? Do you think recalling the operation again in ConnectivityLevelChangedCallback is good idea? For example, I call Buddy.get(...) and the process fails with read timed out, my implementation of ConnectivityLevelChangedCallback will call the Buddy.get(...) again when it is reconnected.

Bradley Serbus
June 7, 2016

Hi Issac,
Yes you are correct, all you should need to do is call Buddy.init(). You should retry if the user can't be depended upon to initiate re-sending data to the server, but I think for most instances allowing the user to retry will be sufficient. For instance, if you time out when doing a create user, showing/hiding 'connection issues' UI in your callback will allow them to attempt the operation again, if you keep the create user UI up until you get a success back from the server. Same goes for other app-specific information. It would be interesting to test against a reliable wi-fi connection to see if you still get the same timeouts. If you'd like, send along some of your code to [email protected], and I can take a look to see if I can find anything amiss.
Thanks,
Brad

Issac Chua
June 7, 2016

Yes, you are right about that. I guess will just let the user to retry again would be good enough. Thanks for your help!

Alexiz Hernandez
June 23, 2016

I am having the same issue. I used Buddy.init(); in my MainActivity. Whenever I login or create user, I redirect to MainActivity and Buddy.getCurrentUser returns the user but if I close the application and launch again, it sends me to LoginActivity again.

Bradley Serbus
June 25, 2016

HI Issac,

I've tracked down a compatibility issue in the Android SDK that can produce the behavior you are seeing. To resolve it, I've tightened up the naming on the file that stores the user token, to ensure that it can be read. I've released a new version of the SDK, 3.0.6. If you are using the '+' convention when specifying the SDK in your Gradle/Maven files ('com.buddy:androidsdk:3.0.0+'), you should pick it up automatically. Let me know if this resolves the issue for you.

Thanks,
Brad

Markdown is allowed