Bypass login if user already created account - ios

the reason I am asking this question is because I am not using firebase or parse to create accounts. I have used my own code to use CloudKit to login and so on. My question is, after the first time opening the app, and the user making an account, how can I make sure that the following time they open the app, it bypasses the login page? And then, if they logout, the next time they open the app, it takes them to the login page. How can this be done.
TL;DR how can I track whether or not a user has been logged in, and then open the app to a 2 possible scenes based on whether or not they are or are not logged in.

Firstly, you could keep the user sign in data (like a returned authkey, or a boolean flag) in the Defaults for the app.
Secondly, you could make a "Loading View" where you would check if that data is present.
Lastly, if the data isn't present move him to the login view, else to the main app.

Related

check keychain is empty or not at start of app

I am building a password management app using objective c and it has two views, with sign up view being the initial/startup view and login view another.
Once the user registers with the app, i am saving the username and password in keychain.
I want to implement a functionality where, when the app launches, it checks if any user exist and if yes it should not show me sign up screen but instead show me login screen.
However i am not able to check wether keychain is empty or not when the app starts.
Please advice how can i do this functionality?

iPhone app crashes when it automatically tries to login to a deleted account

I built an app using Firebase, and I have persistenceEnabled turned on for caching data and auth sessions, etc.
I have a user who, every time he opens the app, it tries to login and load using the saved auth session, but his account was deleted, so it crashes.
He tried deleting the app, turning off the phone, even doing a hard reset by holding down the power and home button at the same time. But every time he opens the app, it still crashes on trying to load the persisted session data.
Is there any way to clear this data out short of restoring the phone back to its factory default settings or releasing a new version of the app?
Unfortunately, Firebase stores account credentials in the keychain and there appears to be no way for the end user to remove them (see this other question).
(If you're looking for a way to programmatically remove them, you should be able to call [ref unauth] or similar and Firebase will clear them.)

Social login when app becomes active after suspension state

I have been struggling with this question and cannot seem to find a clean answer for. I am using social login in an app I am writing (my first). After the app launch, the user gets authenticated with his choice of a social network, in particular, Facebook. when a user suspends the IOS app for days, and returns to it, the app returns right where the user left off, away from the initial login mechanism and the login viewController. How and where do you attempt to verify if the user Facebook token changed (due to password change) or expired? from what I understand you have to make a social graph api request, but does that mean I have to implement this request in every viewController in my app? I am under the impression that when the app becomes active it will only load the viewController displayed before the suspension. Maybe I am wrong.
your input is greatly appreciated.
Regards
So I do have controller over what I present when an app becomes active. I can simply present in the window the login view controller. I can silently verify the credentials. if pass present the next view controller. if not present the login page for the user interaction.
cheers

Proper way to keep Phonegap-Facebook-Plugin / Facebook JS api user logged in to app?

I'm using the Phonegap-Facebook-Plugin to log people in to a phonegap app, and the app keeps kicking the user out to the login page after some time. What's the proper way to keep a user logged in when the re-open the app? Should I check to see if they're logged in still when their re-open the app, and automatically log them back in if they aren't? Or is there a way to keep them logged in over longer periods of time?
Thanks for any help!
One way to do that is to rely on the HTML5 local storage. Create a local key/value and stick testing over it.
After logging in:
window.localStorage.setItem('isLoggedIn','true');
In index.html, check your local storage value:
if ( window.localStorage.getItem('isLoggedIn') === 'true'){
// User is already logged in, he shouldn't be here. Move him from this screen
}
After logging out:
window.localStorage.setItem('isLoggedIn','false');

Control flow for a webservice-backed iOS App

I'm learning the basics of iOS development, and I'd like to make a simple application that connects to a web service. I've got a lot of experience on the web application side, so I'm comfortable with what kinds of requests the app needs to send/receive etc. The part I'm not sure about is what the big picture architecture of a service-backed mobile application looks like.
When my application runs, I have one major requirement: the user must authenticate into the web service. The web service can send back a token and the app can use this for all subsequent requests. I want the user to be able to log in once, and for the app to stay logged in (ie the token remains valid for that device) indefinitely unless they log out.
Until the user logs in the application should really just be a login screen. If they log out, the same. Otherwise, they don't need to see the login screen at all.
So my question is, what is the right way to structure this?
In AppDelegate, do I want to make a LoginViewController and set it to the rootViewController? Then if the user is logged in, push to the main view for the rest of the app?
Or do I want to initialize the main part of the app (for instance, a UITabBarController with a few views in it), and check for a token, and then display a modal login screen if no token is available?
What I'm not clear on is what the rootViewController should be for an application like this, and how the app should keep track of whether the user is logged in, and determine what screen to show when the app is opened.
If anyone can give me a high level overview of how such an app should be structured, I'd really appreciate it.
Thanks!
There isn't really a right way to do this, either flow could be appropriate for an application. If I had some UI or data that would be displayed if a user is not logged in then I would use that as the initial rootViewController and use a modal login dialog to force the user to login. On the other hand, if I had nothing to display until a user has logged in then I would setup the login view controller to be the initial rootViewController if the user is not currently logged in.
For keeping track of the user being logged in you should leverage NSUserDefaults to persist the authentication token. Then in the application:didFinishLaunchingWithOptions: call to your app delegate look for this token in NSUserDefaults (and possibly validate it with the server) then set the rootViewController as appropriate.

Resources