Learning backbone.js and require.js started.
Not sure how to structure files for a web application with user authentication.
It seems like it should flow like this:
- In the init application, a request server to check the status of an authentication session;
- Q # 1: where should I write this code βafter initβ of the session - in /js/app.js?
- Q # 2: should I use jQuery ajax for this or are there any better backbone.js methods (I saw links to get (), fetch (), toJSON () in the examples)?
- If successful, save auth data in the model (user_id, username, auth_token).
- Q # 3: how / where can I create this model so that I can access this data in all modules? i.e. I will have a view to display a template for 'isLoggedIn.html' that will read "Hello% username%! Logout". I want to access the username field from this model. Currently, I only see how to create a new model by specifying it in the define [] view, so I donβt know how to access the model created during init.
- Will use jQuery $ .cookies to save and retrieve auth data, so if a user leaves the page and returns, I can ask the server to check the session, and not to re-login.
- Q # 4: how to include the jquery.cookies.js plugin in this requirejs application to use $ .cookies later, as usual? Should I add this plugin to the define [] list? Should I add it to the /js/jquery/loader.js file?
Thank you for your help.
Edit: I used files from modular-backbone to create my web application. Therefore, when I talk about /js/app.js and js / router.js, the files I refer to.
codemonkey613
source share