javascript - prevent users to navigate back to specific routes with backbone -
i new backbone , want implement simple auth using backbone router.
i using router backbone in app. when start app render login view , init backbone router (backbone.history.start();)
if login succeeded phone call router.navigate('mainmenu', { trigger: true, replace: false });
navigate new route render main menu, when click on browser's button navigate login view.
before navigating previous view (the login view) want inquire user if wants logout first, , if logout process goes well, redirected login view.
how can accomplish that? checked few other questions, reply complicated utilize case. want prevent users navigate specific views if they're logged in.
@dethariel answer. implemented kind of session, using built-in backbone router. started little illustration snippet backbone.router execute method backbone router execute snippet , did similar bellow:
var router = backbone.router.extend({ // define routes , calkbacks // .... // define routes , calkbacks execute: function(callback, args) { // execute called before callback each specific route // next route in here var nextroute = backbone.history.fragment; if(user.loggedin()){ // check if nextroute '#login*'. create other checks if(nextroute.indexof('login')>-1) prompt('log out?'); // else go on routing else if (callback) callback.apply(this, args); } else if (callback) callback.apply(this, args); } });
this minimal, , don't think it's best or secure way, it's starting point me.
javascript backbone.js routes
No comments:
Post a Comment