Url session token easy or not?

I’m not even sure what to call the thing so I’m having trouble searching for it. This is my first ember project so of course its got something unconventional about it. I need a url tokenish thing that users can bookmark, rather than login. Its also sharable.

http://domain.com/TOKEN/some/route/1
http://domain.com/TOKEN/some/other/route/1

Where token is probably a uuid. When the user first comes to the site a uuid is created for them. If they want to get back to their edits they bookmark the url, which they can also share.

Is there some magical way to implement this in ember.js? Is it just a simple as a top level route and this token is exported to everything else through “needs”

Top level route with dynamic segment works. You can use the beforeModel hook to make sure it’s there. It maybe easier to store the token in a service and inject that service in your routes/controllers etc as session for easy access. Easy access meaning in your templates routes controllers etc you can access the session by get(‘session.token’) or in templates {{session.token}}. You can store it in the above mentioned beforeModel hook.

Let me know if that makes sense or just sounds like gibberish…

I would suggest using query params to solve this problem, as routes are more closely tied to template nesting, so are more about what is on screen. You can solve this with a top level route but it will probably cause more problems than it solves

@alexspeller after reading your comment you made me think about this a little more.

I think you’re correct that for normal authentication situations it makes sense to use a query param for a token but in this case the “token” is much more similar to an id in it’s functionality at least thus far.

@kswope I think i would revise my initial comment to say if you’re going to keep this token thing behaving like an id then a top level route is really all you need and you could probably even ignore my service stuff since it’s not really authentication. But if you want to treat it more like authentication then you should go with @alexspeller’s suggestion and use query parameters.

So far I have this. I surely expect something to bite me in the *** soon, but this is so simple I couldn’t resist. Later on, all I expect to want to do is access the session id in nested routes and use it to ‘supplement’ default data, probably with something like an outer join at the backend.

If feels weird that in ember.js routes are so model-centric yet I’m using it more as conventional controller. Doesn’t the ember.js way make allowances for routes that are more heavy on ‘control’ and light on data?

# in router.js
export default Router.map(function() {                                                                                                            
     this.route('session', { path: '/:uid' });                                                                                                       
   }); 

# in app/routes/index.js

 export default Ember.Route.extend({                                                                                                               
     beforeModel: function() {                                                                                                                       
       this.transitionTo("session", uuid.v1());                                                                                                      
     }                                                                                                                                               
   }); 

@kswope to me routers are the C in MVC for ember. Especially now, with data down actions up data and the controller turning into a component, I’ve been moving a lot of things that I started by putting in the controller into the route. I view the “Controller” as more of a place to put view logic rather than a an interface between model and view. That’s my take at least.