Permalink
Browse files

FastBoot Compatibility (#1035)

* DRAFT - Fastboot compatibility

* improve fastboot support

* add FastBoot info to README

* fix tests

* better name for api host conf setting

* WIP: fixing tests

* fix tests

* Use version of ember-cookies with fix for fasboot

* ember-cookies 0.0.6

* fix config for fastboot

* never abort current transition in FastBoot

* don't abort transitions in FastBoot

* Fastboot Feature Branch (#1032)

* ignore store events while the session is busy (#965)

* 1.1.0-beta.5

* 1.1.0

* Check for resourceName in response in Devise Authenticator

* change cookie default key names to be rfc2616 compliant (#978)

fixes #977

* Test for session service data being set with Ember.set (#972)

* code/docs cleanup

* Add tokenRefreshOffset property to OAuth2PasswordGrantAuthenticator (#840)

tokenRefreshOffset determines the offset seconds before the token
expiration to refresh the token. This is randomized so as to reduce
race conditions between multiple tabs from refreshing at the same time.

This is configurable because in some cases, the offset randomization
needs to be increased to decrease the probability of the above mentioned
race conditions.

Once more case would be in slow internet connections, you make a call to
refresh the token but the server doesn't process it in time (or receive
it in time), the server will check and the token that you sent up is now
expired so the refresh will fail.

* cleanup transition usage in authenticated and unauthenticated route mixins (#992)

no issue
- fixes potential test timing issue
- removes unecessary abort call

* [BUGFIX] Remove Ember.Logger (#993)

Ember.Logger is not substituted by noops in production.

More info in emberjs/guides#1467

* [WIP] Validate server responses in authenticators (#957)

* Validate response data in devise authenticator

* Validate response data in OAuth2 authenticator

* Add tests for oauth2 data validations

* Add tests for devise data validations

* Remove unncessary validations

* Refactor 'restore' in devise authenticator

* Fix test timeout errors

* Minor cleanup

* Consider resource name when validating response

* Refactor devise authenticator _validate method

* update dependencies (#1004)

This updates Ember, Ember Data, Ember CLI etc. to the latest
versions. This also fixes a lot of JSCS warnings that were introduced
by the latest version of ember-suave.

* Use the term "squash" when referring to collapsing commits into one (#1011)

That's consistent with the term used in git-rebase and with the general public.

* Add rejectWithXhr to optionally reject with XHR vs response body (#1012)

Allows ember apps using ember-simple-auth to receive the whole XHR object if the backend fails, instead of the response body, if they so choose.

In the case of OAuth 2.0 backends, it's been a pattern in the wild to use X- headers to send context as to why a grant has failed. Examples include API throttling, brute force lockouts, and OTP/two-factor authentication information.

Selfishly, I require this change so my application can be notified when the API has locked out an account due to suspicious activity via an X- header.

The decision to expose it as an option was chosen so backwards compatibility is maintained and keeps the addon simple for those who need not be concerned with complex backends.

* Add fastboot-dist to npmignore (#1015)

* Optionally send custom headers in authentication call (#1018)

Complex systems that offer Two Factor Authentication with their OAuth 2.0 implementation need to send additional context via the HTTP headers. This pattern has been observed in the wild by such systems such as GitHub. Because of the restrictions of OAuth 2.0 RFC, only headers can be used for additional context, not request/response bodies.

This could be seen as a counterpart to #1012, where using both features allow bi-directional context enabling 2FA, brute force lockouts, etc.

* [fastboot-compatibility] initial work

* [fastboot-compatbility] improve support

* [fastboot-compatibility] Use ember-cookies@0.0.7

ember-cookies 0.0.6

ember-cookies@0.0.7

* [fastboot-compatbility] fix ember-build-cli.js

* [fastboot-compatibility] fix route mixin transitions

* [fastboot-compatibility] Update `session-stores/cookie` with `typeof` guard (#1)

* [fastboot-compatiblity] fix tests

* Use apiHost config for dummy app.

better name for api host conf setting

fix dummy app API endpoints

* Helpful instructions for `npm run fastboot`

* Restore cookie session renewal

* Fix various rebase issues

* ember-cli-fasboot@1.0.0-beta.7

* Fix tests for fastboot feature branch (#1034)

* fix my messed up rebase 😳

* fix cookie store

* [Fastboot] Remove inject of cookies in initializer; Bump ember-cookies; Add fastboot host whitelist (#1039)

* Add fastboot host whitelist

* Bump ember-cookies to make dummy app work

* Remove inject of cookies in initializers

* [Fastboot] Integration testing for fastboot (#1045)

* Add session register back

* Create a fastboot test app and create basic tests against fastboot.

* fix bad merge 😞

* I suck at merging 😱

* we might need to cleanup for the node tests…

* run both node test and FastBoot node test

* fix node tests

* increase timeout for fastboot node tests

* Update OAuth2PasswordGrant Authenticator to use Fetch (#1066)

* Using ember-network fetch for the oauth2 password grand authenticator

* Fixing unit tests for adding fetch to ember simple auth

* Changing naming of rejectWithRequest to rejectWithResponse

* Making rejectWithXhr a deprecatingAlias and adding import-polyfill to the node-tests app

* docs fixes

* don't bind to localStorage events in FastBoot

* fix test

* don't use window.location in fastboot

* update docs for fastboot

* use ember-network in devise authenticator

* fix tests

* rename fastboot app fixture

* rename fastboot test

* WIP: FastBoot regression test

* WIP: FastBoot regression test

* fix adaptive store for fastboot

* Merge branch 'master' into fastboot (#1098)

* Merge branch 'master' into fastboot

* Remove unneeded test

* Refactor to use ember-cookies clear()

* Try fix for 1.12

* Cleanup

* Cookie store `_secureCookies`: use correct protocol property in FastBoot mode (#1104)

* Merge latest master into fastboot (#1110)

* Update managing-current-user.md (#1068)

Avoid making a current user request if not authenticated

* Add explanatory comment to application route (#1069)

The setup-session-restoration initializer needs the application route to be explicitly defined in the consuming app, so simple auth must ship with this file in case the consuming app hasn't defined their own. However, if the consuming app has another addon that also provides an application route via it's app folder, simple auth may override that addon's file with this one, depending on the load order.

This is easily fixed by specifying an explicit load order (i.e. `after: 'ember-simple-auth'`). However, because the contents of this file are completely generic, and Ember's build process merges this file into the app folder without retaining source information, it's difficult to know from the consuming app's perspective that simple-auth is the addon providing this generic file (and therefore the `after` option needs to specify "ember-simple-auth").

This adds an explanatory comment, hopefully making it a bit clearer in case anyone is trying to figure out where this empty application route file is coming from.

* Cookie store rewrite (#1056)

* Persist to cookie when relevant attributes change

* Refactor cookie properties on adaptive store

* Fix cookie store getters and setters

* Fix adaptive store test

* Remove unused code

* Fix cookie properties on adaptive store

* Change cookie properties to adaptive store

* Fix cookie setters

* Fix jshint errors

* Remove unused code

* Wrap `rewriteCookie` in Ember.run.scheduleOnce

* Remove extra run.scheduleOnce

* Remove unnecessary jshint ignores

* Minor cleanup

* Fix cookie domain test

* Add tests for rewrite behavior

* Save WIP on shared cookie behavior

* fix cookie store rewrite behavior tests

* Small fixes (#1047)

* Fix jshint error

* Allow cookie to write blank values on clear

* Restore previous cookieDomain test

* Persist value in test so cookie will write

* Fix cookie domain test

* simplify AdaptiveStore code

* simplify cooke store code

* use CPs consistently internally

* code cleanup

* handle changes of cookie name correctly

* no need to clear before rewrite

* clear old expiration cookie as well

* Include path when deleting cookie (#1067)

* Refactor cookie string (#1074)

* Include path when deleting cookie

* Add a cookie string method

* Should `resolve` after fetching user. (#1077)

* Should `resolve` after fetching user.

Else the promise remains unresolved.

* Remove return as suggested in the review

* Remove yet another return as suggested

* Update "ember-cli-mocha" to v0.12.0 (#1105)

* Update "ember-cli-mocha" to v0.12.0

* tests: Import it() from "mocha"

* tests: Use new testing API in ember-mocha

* Fix OAuth2 authenticator tokenRefreshOffset (#1106)

* Fix OAuth2 authenticator tokenRefreshOffset

* Fix lint mistake

* Ensure correct root url handling (#1070)

* set rootURL on router correctly

* document readonly correctly

* use rootURL if present

* Fix typo (#1109)

* cleanup

* remove unnecessary injection

* remove unnecessary property

* fix dependency versions

* use cookie session store in dummy app
  • Loading branch information...
1 parent 227fa7f commit 75cd83b239f1950916450e1e4e89ac7056d823d9 @marcoow marcoow committed on GitHub Dec 6, 2016
Showing with 1,158 additions and 359 deletions.
  1. +1 βˆ’1 .travis.yml
  2. +16 βˆ’1 README.md
  3. +32 βˆ’22 addon/authenticators/devise.js
  4. +45 βˆ’20 addon/authenticators/oauth2-password-grant.js
  5. +1 βˆ’0 addon/initializers/setup-session.js
  6. +13 βˆ’2 addon/mixins/application-route-mixin.js
  7. +12 βˆ’1 addon/mixins/authenticated-route-mixin.js
  8. +16 βˆ’3 addon/mixins/unauthenticated-route-mixin.js
  9. +19 βˆ’2 addon/session-stores/adaptive.js
  10. +54 βˆ’47 addon/session-stores/cookie.js
  11. +16 βˆ’2 addon/session-stores/local-storage.js
  12. +6 βˆ’6 bower.json
  13. +4 βˆ’0 docs/theme/assets/css/main.css
  14. +1 βˆ’1 docs/theme/partials/events.handlebars
  15. +1 βˆ’1 docs/theme/partials/method.handlebars
  16. +1 βˆ’1 docs/theme/partials/props.handlebars
  17. +2 βˆ’5 ember-cli-build.js
  18. +33 βˆ’44 node-tests/blueprints/authenticator-test.js
  19. +28 βˆ’33 node-tests/blueprints/authorizer-test.js
  20. +34 βˆ’0 node-tests/fastboot-runner.js
  21. +47 βˆ’0 node-tests/fastboot/graceful-regression-test.js
  22. +72 βˆ’0 node-tests/fastboot/integration-test.js
  23. +2 βˆ’1 node-tests/fixtures/app/package/package.json
  24. +20 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/app.js
  25. +25 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/authenticators/auth.js
  26. 0 node-tests/fixtures/fastboot-ready-app/app/components/.gitkeep
  27. 0 node-tests/fixtures/fastboot-ready-app/app/controllers/.gitkeep
  28. +11 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/controllers/application.js
  29. +25 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/index.html
  30. +3 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/resolver.js
  31. +17 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/router.js
  32. 0 node-tests/fixtures/fastboot-ready-app/app/routes/.gitkeep
  33. +6 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/routes/application.js
  34. +11 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/routes/authenticate.js
  35. +12 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/routes/invalidate.js
  36. +6 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/routes/login.js
  37. +6 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/routes/protected.js
  38. +3 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/session-stores/application.js
  39. 0 node-tests/fixtures/fastboot-ready-app/app/styles/app.css
  40. +3 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/templates/application.hbs
  41. +1 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/templates/authenticate.hbs
  42. 0 node-tests/fixtures/fastboot-ready-app/app/templates/components/.gitkeep
  43. +1 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/templates/index.hbs
  44. +4 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/templates/login.hbs
  45. +6 βˆ’0 node-tests/fixtures/fastboot-ready-app/app/templates/protected.hbs
  46. +50 βˆ’0 node-tests/fixtures/fastboot-ready-app/config/environment.js
  47. +20 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/app.js
  48. +25 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/authenticators/auth.js
  49. 0 node-tests/fixtures/not-fastboot-ready-app/app/components/.gitkeep
  50. 0 node-tests/fixtures/not-fastboot-ready-app/app/controllers/.gitkeep
  51. +11 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/controllers/application.js
  52. +25 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/index.html
  53. +3 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/resolver.js
  54. +17 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/router.js
  55. 0 node-tests/fixtures/not-fastboot-ready-app/app/routes/.gitkeep
  56. +6 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/routes/application.js
  57. +6 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/routes/login.js
  58. +6 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/routes/protected.js
  59. 0 node-tests/fixtures/not-fastboot-ready-app/app/styles/app.css
  60. +3 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/templates/application.hbs
  61. +1 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/templates/authenticate.hbs
  62. 0 node-tests/fixtures/not-fastboot-ready-app/app/templates/components/.gitkeep
  63. +1 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/templates/index.hbs
  64. +4 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/templates/login.hbs
  65. +6 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/app/templates/protected.hbs
  66. +50 βˆ’0 node-tests/fixtures/not-fastboot-ready-app/config/environment.js
  67. +14 βˆ’2 package.json
  68. +4 βˆ’0 server/index.js
  69. +1 βˆ’0 server/mocks/accounts.js
  70. +2 βˆ’1 tests/acceptance/authentication-test.js
  71. +3 βˆ’1 tests/dummy/app/adapters/application.js
  72. +3 βˆ’1 tests/dummy/app/authenticators/oauth2.js
  73. +3 βˆ’0 tests/dummy/app/session-stores/application.js
  74. +17 βˆ’10 tests/dummy/config/environment.js
  75. +34 βˆ’0 tests/helpers/fake-cookie-service.js
  76. +24 βˆ’38 tests/unit/authenticators/devise-test.js
  77. +64 βˆ’73 tests/unit/authenticators/oauth2-password-grant-test.js
  78. +4 βˆ’1 tests/unit/mixins/authenticated-route-mixin-test.js
  79. +4 βˆ’1 tests/unit/mixins/unauthenticated-route-mixin-test.js
  80. +43 βˆ’11 tests/unit/session-stores/adaptive-test.js
  81. +11 βˆ’4 tests/unit/session-stores/cookie-test.js
  82. +3 βˆ’1 tests/unit/session-stores/local-storage-test.js
  83. +74 βˆ’22 tests/unit/session-stores/shared/cookie-store-behavior.js
View
@@ -35,7 +35,7 @@ install:
script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- - ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
+ - ember try:one $EMBER_TRY_SCENARIO test && npm run nodetest && npm run fastboot-nodetest
notifications:
email: false
View
@@ -540,7 +540,9 @@ store if `localStorage` is available.
[The Cookie store](http://ember-simple-auth.com/api/classes/CookieStore.html)
stores its data in a cookie. This is used by the adaptive store if
-`localStorage` is not available.
+`localStorage` is not available. __This store must be used when the
+application uses
+[FastBoot](https://github.com/ember-fastboot/ember-cli-fastboot).__
#### Ephemeral Store
@@ -590,6 +592,19 @@ export default Base.extend({
});
```
+## FastBoot
+
+Ember Simple Auth works with FastBoot out of the box as long as the Cookie
+session store is being used. In order to enable the cookie store, define it as
+the application store:
+
+```js
+// app/session-stores/application.js
+import CookieStore from 'ember-simple-auth/session-stores/cookie';
+
+export default CookieStore.extend();
+```
+
## Testing
Ember Simple Auth comes with a __set of test helpers that can be used in
@@ -1,9 +1,12 @@
import Ember from 'ember';
import BaseAuthenticator from './base';
+import fetch from 'ember-network/fetch';
-const { RSVP: { Promise }, isEmpty, run, $: jQuery, assign: emberAssign, merge } = Ember;
+const { RSVP: { Promise }, isEmpty, run, assign: emberAssign, merge } = Ember;
const assign = emberAssign || merge;
+const JSON_CONTENT_TYPE = 'application/json';
+
/**
Authenticator that works with the Ruby gem
[devise](https://github.com/plataformatec/devise).
@@ -118,18 +121,25 @@ export default BaseAuthenticator.extend({
data[resourceName] = { password };
data[resourceName][identificationAttributeName] = identification;
- return this.makeRequest(data).then(
- (response) => {
- if (this._validate(response)) {
- const resourceName = this.get('resourceName');
- const _response = response[resourceName] ? response[resourceName] : response;
- run(null, resolve, _response);
+ this.makeRequest(data).then((response) => {
+ if (response.ok) {
+ response.json().then((json) => {
+ if (this._validate(json)) {
+ const resourceName = this.get('resourceName');
+ const _json = json[resourceName] ? json[resourceName] : json;
+ run(null, resolve, _json);
+ } else {
+ run(null, reject, `Check that server response includes ${tokenAttributeName} and ${identificationAttributeName}`);
+ }
+ });
+ } else {
+ if (useXhr) {
+ run(null, reject, response);
} else {
- run(null, reject, `Check that server response includes ${tokenAttributeName} and ${identificationAttributeName}`);
+ response.json().then((json) => run(null, reject, json));
}
- },
- (xhr) => run(null, reject, useXhr ? xhr : (xhr.responseJSON || xhr.responseText))
- );
+ }
+ }).catch((error) => run(null, reject, error));
});
},
@@ -149,25 +159,25 @@ export default BaseAuthenticator.extend({
@method makeRequest
@param {Object} data The request data
- @param {Object} options Ajax configuration object merged into argument of `$.ajax`
- @return {jQuery.Deferred} A promise like jQuery.Deferred as returned by `$.ajax`
+ @param {Object} options request options that are passed to `fetch`
+ @return {Promise} The promise returned by `fetch`
@protected
*/
- makeRequest(data, options) {
- const serverTokenEndpoint = this.get('serverTokenEndpoint');
+ makeRequest(data, options = {}) {
+ let url = options.url || this.get('serverTokenEndpoint');
let requestOptions = {};
+ let body = JSON.stringify(data);
assign(requestOptions, {
- url: serverTokenEndpoint,
- type: 'POST',
- dataType: 'json',
- data,
- beforeSend(xhr, settings) {
- xhr.setRequestHeader('Accept', settings.accepts.json);
+ body,
+ method: 'POST',
+ headers: {
+ 'accept': JSON_CONTENT_TYPE,
+ 'content-type': JSON_CONTENT_TYPE
}
});
assign(requestOptions, options || {});
- return jQuery.ajax(requestOptions);
+ return fetch(url, requestOptions);
},
_validate(data) {
@@ -1,6 +1,7 @@
/* jscs:disable requireDotNotation */
import Ember from 'ember';
import BaseAuthenticator from './base';
+import fetch from 'ember-network/fetch';
const {
RSVP,
@@ -11,7 +12,6 @@ const {
assign: emberAssign,
merge,
A,
- $: jQuery,
testing,
warn,
keys: emberKeys
@@ -137,9 +137,24 @@ export default BaseAuthenticator.extend({
@property rejectWithXhr
@type Boolean
@default false
+ @deprecated OAuth2PasswordGrantAuthenticator/rejectWithResponse:property
@public
*/
- rejectWithXhr: false,
+ rejectWithXhr: computed.deprecatingAlias('rejectWithResponse'),
+
+ /**
+ When authentication fails, the rejection callback is provided with the whole
+ fetch response object instead of it's response JSON or text.
+
+ This is useful for cases when the backend provides additional context not
+ available in the response body.
+
+ @property rejectWithResponse
+ @type Boolean
+ @default false
+ @public
+ */
+ rejectWithResponse: false,
/**
Restores the session from a session data object; __will return a resolving
@@ -209,7 +224,7 @@ export default BaseAuthenticator.extend({
return new RSVP.Promise((resolve, reject) => {
const data = { 'grant_type': 'password', username: identification, password };
const serverTokenEndpoint = this.get('serverTokenEndpoint');
- const useXhr = this.get('rejectWithXhr');
+ const useResponse = this.get('rejectWithResponse');
const scopesString = makeArray(scope).join(' ');
if (!isEmpty(scopesString)) {
data.scope = scopesString;
@@ -228,8 +243,8 @@ export default BaseAuthenticator.extend({
resolve(response);
});
- }, (xhr) => {
- run(null, reject, useXhr ? xhr : (xhr.responseJSON || xhr.responseText));
+ }, (response) => {
+ run(null, reject, useResponse ? response : response.responseJSON);
});
});
},
@@ -283,29 +298,39 @@ export default BaseAuthenticator.extend({
@param {String} url The request URL
@param {Object} data The request data
@param {Object} headers Additional headers to send in request
- @return {jQuery.Deferred} A promise like jQuery.Deferred as returned by `$.ajax`
+ @return {Promise} A promise that resolves with the response object`
@protected
*/
makeRequest(url, data, headers = {}) {
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
+
+ const body = keys(data).map((key) => {
+ return `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
+ }).join('&');
+
const options = {
- url,
- data,
- type: 'POST',
- dataType: 'json',
- contentType: 'application/x-www-form-urlencoded',
- headers
+ body,
+ headers,
+ method: 'POST'
};
const clientIdHeader = this.get('_clientIdHeader');
if (!isEmpty(clientIdHeader)) {
merge(options.headers, clientIdHeader);
}
-
- if (isEmpty(keys(options.headers))) {
- delete options.headers;
- }
-
- return jQuery.ajax(options);
+ return new RSVP.Promise((resolve, reject) => {
+ fetch(url, options).then((response) => {
+ response.text().then((text) => {
+ let json = text ? JSON.parse(text) : {};
+ if (!response.ok) {
+ response.responseJSON = json;
+ reject(response);
+ } else {
+ resolve(json);
+ }
+ });
+ }).catch(reject);
+ });
},
_scheduleAccessTokenRefresh(expiresIn, expiresAt, refreshToken) {
@@ -340,8 +365,8 @@ export default BaseAuthenticator.extend({
this.trigger('sessionDataUpdated', data);
resolve(data);
});
- }, (xhr, status, error) => {
- warn(`Access token could not be refreshed - server responded with ${error}.`);
+ }, (response) => {
+ warn(`Access token could not be refreshed - server responded with ${response.responseJSON}.`);
reject();
});
});
@@ -13,5 +13,6 @@ export default function setupSession(registry) {
store = 'session-store:test';
registry.register(store, Ephemeral);
}
+
inject(registry, 'session:main', 'store', store);
}
@@ -1,4 +1,5 @@
import Ember from 'ember';
+import getOwner from 'ember-getowner-polyfill';
import Configuration from './../configuration';
const { inject, Mixin, A, run: { bind }, testing, computed } = Ember;
@@ -22,7 +23,7 @@ const { inject, Mixin, A, run: { bind }, testing, computed } = Ember;
applicationRoute.transitionTo('index');
});
session.on('invalidationSucceeded', function() {
- window.location.reload();
+ applicationRoute.transitionTo('bye');
});
};
@@ -52,6 +53,12 @@ export default Mixin.create({
*/
session: inject.service('session'),
+ _isFastBoot: computed(function() {
+ const fastboot = getOwner(this).lookup('service:fastboot');
+
+ return fastboot ? fastboot.get('isFastBoot') : false;
+ }),
+
/**
The route to transition to after successful authentication.
@@ -120,7 +127,11 @@ export default Mixin.create({
*/
sessionInvalidated() {
if (!testing) {
- window.location.replace(Configuration.baseURL);
+ if (this.get('_isFastBoot')) {
+ this.transitionTo(Configuration.baseURL);
+ } else {
+ window.location.replace(Configuration.baseURL);
+ }
}
}
});
@@ -1,4 +1,5 @@
import Ember from 'ember';
+import getOwner from 'ember-getowner-polyfill';
import Configuration from './../configuration';
const { inject: { service }, Mixin, assert, computed } = Ember;
@@ -33,6 +34,12 @@ export default Mixin.create({
*/
session: service('session'),
+ _isFastBoot: computed(function() {
+ const fastboot = getOwner(this).lookup('service:fastboot');
+
+ return fastboot ? fastboot.get('isFastBoot') : false;
+ }),
+
/**
The route to transition to for authentication. The
{{#crossLink "AuthenticatedRouteMixin"}}{{/crossLink}} will transition to
@@ -72,7 +79,11 @@ export default Mixin.create({
let authenticationRoute = this.get('authenticationRoute');
assert('The route configured as Configuration.authenticationRoute cannot implement the AuthenticatedRouteMixin mixin as that leads to an infinite transitioning loop!', this.get('routeName') !== authenticationRoute);
- this.set('session.attemptedTransition', transition);
+ if (!this.get('_isFastBoot')) {
+ transition.abort();
+ this.set('session.attemptedTransition', transition);
+ }
+
return this.transitionTo(authenticationRoute);
} else {
return this._super(...arguments);
@@ -1,4 +1,5 @@
import Ember from 'ember';
+import getOwner from 'ember-getowner-polyfill';
import Configuration from './../configuration';
const { inject: { service }, Mixin, assert, computed } = Ember;
@@ -34,6 +35,12 @@ export default Mixin.create({
*/
session: service('session'),
+ _isFastBoot: computed(function() {
+ const fastboot = getOwner(this).lookup('service:fastboot');
+
+ return fastboot ? fastboot.get('isFastBoot') : false;
+ }),
+
/**
The route to transition to if a route that implements the
{{#crossLink "UnauthenticatedRouteMixin"}}{{/crossLink}} is accessed when
@@ -61,10 +68,16 @@ export default Mixin.create({
@param {Transition} transition The transition that lead to this route
@public
*/
- beforeModel() {
+ beforeModel(transition) {
if (this.get('session').get('isAuthenticated')) {
- assert('The route configured as Configuration.routeIfAlreadyAuthenticated cannot implement the UnauthenticatedRouteMixin mixin as that leads to an infinite transitioning loop!', this.get('routeName') !== this.get('routeIfAlreadyAuthenticated'));
- this.transitionTo(this.get('routeIfAlreadyAuthenticated'));
+ let routeIfAlreadyAuthenticated = this.get('routeIfAlreadyAuthenticated');
+ assert('The route configured as Configuration.routeIfAlreadyAuthenticated cannot implement the UnauthenticatedRouteMixin mixin as that leads to an infinite transitioning loop!', this.get('routeName') !== routeIfAlreadyAuthenticated);
+
+ if (!this.get('_isFastBoot')) {
+ transition.abort();
+ }
+
+ return this.transitionTo(routeIfAlreadyAuthenticated);
} else {
return this._super(...arguments);
}
Oops, something went wrong.

0 comments on commit 75cd83b

Please sign in to comment.