These are chat archives for jdubray/sam

Jun 2017
Johan Alkstål
Jun 06 2017 20:28

If a redirect is required, for instance a user is authenticated, their state is added to the model and now they need to be redirected from the log in page to the start page,

where would it be appropriate for that to happen?

I was first thinking of it being a next action from state, but actions are for proposing updates to the model.

Either my current url is also in the model (not sure about that), or the decision to redirect is taken elsewhere.

What do you think?

Daniel Neveux
Jun 06 2017 21:48
I split nap into services which react to model mutations. I have already done this by making a router service which watches the model then pushes the new url.
Jean-Jacques Dubray
Jun 06 2017 21:57

@johanalkstal I only use social login (gmail, facebook,..) but I have to assume it works the same either way.
My initial model starts with:

   model = { needsLogin: true ; }

( I use this trick where the initial model is returned by the server as a model.js file).

See import {data} from '../app/v1/model.js'which is returned by the server
I simply redirect to the login page if needsLogin:
if (data.needsLogin) {
        window.location.replace('login.html') ;
That's outside the SAM loop. Then when you redirect to index.html the model.js "file" is now generated with the proper content when the user is authenticated.
I think it's a bit overkill to run that phase in the SAM loop.