Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cookies #19

Merged
merged 6 commits into from
Feb 24, 2016
Merged

Handle cookies #19

merged 6 commits into from
Feb 24, 2016

Conversation

tomdale
Copy link
Contributor

@tomdale tomdale commented Feb 23, 2016

This slightly changes #17 to use the FastBoot service, and does the cookie parsing on the server side.

/cc @rwjblue @marcoow

fastbootService.setProperties({
_request: request,
_response: response,
cookies: cookies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should cookies also be private for now (i.e. _cookies)?

@rwjblue
Copy link
Member

rwjblue commented Feb 23, 2016

LGTM, but I'd like to see this kept as private for now while we settle in on things (same as _request / _response)....

}

fastbootService.setProperties({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has the problem that cookies are only accessible after the application instance has booted (e.g. you cannot use cookies in initializers/instance initializers). Not sure whether using cookies in (instance) initializer should be considered an anti pattern but I guess it might be surprising to people that they can only access cookies after all instance initializers have run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoow Yes, this is definitely a tradeoff of this implementation. I went spelunking in the Ember Application and ApplicationInstance code and it seems there is not an elegant way of setting cookies prior to running instance initializers.

That said, I just re-read the code now and I think I misread last night. I thought that registry creation and running of instance initializers all happened in _bootSync. But actually it looks like __registry__ exists on the application instance before the boot process begins.

I think that means that we could register an object in the registry before the instance initializers are kicked off. It involves reaching pretty deep into private API, so we should think about what we're trying to express here and see if there's an elegant way of exposing it as public API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think restoring authentication state (or user settings etc.) from cookies in (instance) initializers is probably still a pretty common thing to do. In fact, Ember Simple Auth did just that until version 1.0 as well.

I think the ApplicationInstance returned from buildInstance (https://github.com/ember-fastboot/ember-fastboot-server/pull/19/files#diff-ba82abedace362f3becf198dd49dacb4R60) already has the register method so that it should be possible to register the request and response as -request:main and -response:main and inject these into the fastboot service then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoow Yes, I think you're right. I'm in the middle of updating the PR now to attempt this.

@tomdale
Copy link
Contributor Author

tomdale commented Feb 23, 2016

@rwjblue I think it's OK to make cookies public since:

  1. 100% of people who have authenticated apps need it.
  2. The surface area is quite small: it's just a POJO with cookies as key/values.

Given that we're pre-1.0, I think we could get away with changing it if we had to. But given how simple it is, I think it's probably OK.

@rwjblue
Copy link
Member

rwjblue commented Feb 23, 2016

@tomdale - My personal preference is to err on the side of private and make it public once we are certain. I am happy to defer to you on this.

@tomdale
Copy link
Contributor Author

tomdale commented Feb 23, 2016

@rwjblue @marcoow I'm pretty happy with this latest update. Please let me know what you think.

@rwjblue
Copy link
Member

rwjblue commented Feb 24, 2016

Seems good to me.

BTW, I'm starting to feel the desire for some tests in this repo....

@marcoow
Copy link
Contributor

marcoow commented Feb 24, 2016

Looks great! I think in the long term there would have to be a public interface to request and response but it's probably better to keep them (or actually the complete FastBootInfo) private for now and see how everything goes from here.

@tomdale
Copy link
Contributor Author

tomdale commented Feb 24, 2016

@rwjblue FWIW all of these new features I'm working on come with tests in the ember-cli-fastboot repo. There is an extremely tight coupling going on between the two and I don't have a strong sense of how to test FastBootServer without a compiled Ember app, which requires ember-cli-fastboot, which requires ember-fasboot-server, which requires…

That said, yeah, I agree it's problematic. We should try to think of something. We can at minimum probably write a stub Ember app generator that generates the minimum scaffolding required to trick the server into thinking it's running an Ember app.

tomdale added a commit that referenced this pull request Feb 24, 2016
@tomdale tomdale merged commit e3a1082 into master Feb 24, 2016
@tomdale tomdale deleted the handle-cookies branch March 3, 2016 16:05
@marcoow
Copy link
Contributor

marcoow commented Mar 12, 2016

@tomdale: I published (a very early version of) an addon that abstracts cookie access so it works both in the browser as well as with Fastboot here: https://github.com/simplabs/ember-cookies

@tomdale
Copy link
Contributor Author

tomdale commented Mar 14, 2016

@marcoow Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants