How to deal with authenticated state in a SproutCore application -


in (now sort of deleted) question peter kniestedt wondering , how set timer check authentication of user.

his question part of larger question (which title of question). because think important question answered, created new question way gather important information in 1 spot.

this typical case use of statechart, , more concurrent states.

if didn't know already, sproutcore contains useful library called sc.statechart, way of dealing application state in way more controllable through use of boolean properties, acts responder controller.

in case you'd want statechart in root has 2 concurrent states: 1 deal states around authentication, , 1 deal rest of application.

myapp.statechart = sc.statechart.create({   rootstate: sc.state.design({     substatesareconcurrent: true,     auth: sc.state.design({       initialsubstate: 'checkauth',       checkauth: sc.state.design({       }),       login: sc.state.design({       }),       authenticating: sc.state.design({       }),       authenticated: sc.state.design({       }),           }),     appmain: sc.state.design({     })   }) }); 

how supposed work: when app starts, go 2 states @ once, 1 being appmain state state deals application itself. other auth state, go initial substate checkauth, checks whether user has valid session. if not, state should go login state, responsible showing login screen. when user performs login, login state transitions authenticating state, server checking. if attempt invalid or incorrect, authenticating state should transition login, otherwise authenticated.

to answer original question question based on: if need timer somewhere regularly checks whether authentication still valid, should in authenticated state. if fail, can transition login state, display login screen.

using state chart prevents user having reload or quit application in order login again, , possibly lose data result. in short makes better user experience.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -