WiPhone
WiPhone

Reputation: 683

Best worklight practices to logout and to remember a session

I want to know what are the best practices, when using Worklight:

I am using Worklight 6 authentication, with a custom login module, for an Hybrid App (HTML5)

If there is a sample doing all these feature, it will be great, otherwise, any code snippets and advices should help me.

Thanks

Upvotes: 3

Views: 482

Answers (1)

jnortey
jnortey

Reputation: 1625

Can't exactly say that these are 'best practices', but this is what I would do in these situations:

To Logout

Don't have much to say here. Clear anything and everything that the user could use to access resources on the server, including cookies. As you probably know, the login modules come with a logout function call where you can perform these operations.

To Maintain the user logged in, after application relaunch

After the first login, use some local storage mechanism, such as JSONStore, in order to save the credentials. JSONStore can encrypt all data saved locally as well. When the user starts the app, instead of prompting for login credentials, check the local storage to see if the credentials already exist and then send them to the server to log in.

To login a user directly after an account creation

I'd use a similar approach as above. When the user sends their account information to the server, save it to local storage. If the account creation was successful, then the server can send a success response to the client which can then automatically send the credentials back to the server to log them in. If the server sends a failure response, then the credentials should be deleted from the local store and the user will be prompted to try to register again.

Upvotes: 4

Related Questions