Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if user is logged in or not after OnlineIdConnectedStateChange has triggered

I am working on a Windows 8.1 Metro app. The app gives a personalized experience to the user who is logged in to Windows with his Live account.

As provided in Windows, any user can connect/disconnect his live account to the PC via PC Settings -> Account. My requirement is to be notified at this event, i.e., whenever user connects/disconnects his live account to PC. Now, as per MSDN page (http://msdn.microsoft.com/en-us/library/windows/apps/hh977056.aspx) this event would trigger OnlineIdConnectedStateChange. I was able to implement a background task in the app that listens to the trigger and it is working perfectly fine. Everytime, a change occurs in connected Live account, the event listener is fired. But I am not able to determine the fact if the user logged in with some Live account or logged out from an already connected account.

I tried using Windows.Security.Authentication.OnlineId.OnlineIdAuthenticator as mentioned in (Metro App - How to detect if logged in with Live ID or Local Account) but this triggers the Authentication flow if no user is logged in. This is not what I want. I just want to know the fact if someone is logged in or not. I don't want to trigger an Auth flow.

Is there any way to determine the logged in/out status of the user when the OnlineIdConnectedStateChange event is fired in the background task?

Thanks for any help.

like image 430
Nishchay Sharma Avatar asked Feb 12 '14 14:02

Nishchay Sharma


1 Answers

You can always store the last userId of the user that successfully logged in. Then compare that Id with the current userId, if it's null then the user logged out, if not the same then it's a new user.

Edit:

  1. User opens the app 1.a: User logs in => store some flag or userId (some info basically) 1.b: User does not log in => store some null flag or null userId

  2. User closes app

  3. Backgroundworker picks up the event, based on the flag or info you can figure out if the user logged in or logged out.

Depending on what you store, you can use AppSettings or IsolatedStorage among other options to store the flag.

like image 76
AD.Net Avatar answered Nov 15 '22 02:11

AD.Net