Merge pull request #410 from hashicorp/fix-origin-auth-bug
fix: 🐛 fix auth reset bug in desktop due to init before origin
This commit is contained in:
7 files changed
+52
-17
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { getOwner } from '@ember/application';
|
||||
|
||||
export function initialize(registry) {
|
||||
|
||||
// Lookup the application route
|
||||
const ApplicationRoute = registry.resolveRegistration
|
||||
? registry.resolveRegistration('route:application')
|
||||
: registry.resolve('route:application');
|
||||
|
||||
ApplicationRoute.reopen({
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
const originalBeforeModel = this.beforeModel;
|
||||
|
||||
// Override the beforeModel hook and initialize the origin
|
||||
this.beforeModel = async function() {
|
||||
const origin = getOwner(this).lookup('service:origin');
|
||||
return origin.updateOrigin().then(
|
||||
() => originalBeforeModel.apply(this, arguments),
|
||||
() => originalBeforeModel.apply(this, arguments)
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
after: 'ember-simple-auth',
|
||||
initialize
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { inject as service } from '@ember/service';
|
||||
export default class IndexRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
@service origin;
|
||||
|
||||
// =methods
|
||||
|
||||
@@ -12,7 +12,7 @@ export default class IndexRoute extends Route {
|
||||
* If no origin is specified yet, redirects to origin, otherwise scopes.
|
||||
*/
|
||||
redirect() {
|
||||
const rendererOrigin = this.session.data.origin;
|
||||
const rendererOrigin = this.origin.rendererOrigin;
|
||||
if (!rendererOrigin) {
|
||||
this.replaceWith('origin');
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class OriginService extends Service {
|
||||
|
||||
@service ipc;
|
||||
@service store;
|
||||
@service session;
|
||||
@service storage;
|
||||
|
||||
// =attributes
|
||||
|
||||
@@ -23,14 +23,14 @@ export default class OriginService extends Service {
|
||||
* @type {?string}
|
||||
*/
|
||||
get rendererOrigin() {
|
||||
return this.session.data.origin;
|
||||
return this.storage.getItem('origin');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?string} origin
|
||||
*/
|
||||
set rendererOrigin(origin) {
|
||||
this.session.set('data.origin', origin);
|
||||
this.storage.setItem('origin', origin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const APP_NAME = process.env.APP_NAME || 'Boundary';
|
||||
const API_HOST = process.env.API_HOST || '';
|
||||
const ENABLE_MIRAGE = process.env.API_HOST ? false : true;
|
||||
const ENABLE_MIRAGE = process.env.ENABLE_MIRAGE ? false : true;
|
||||
|
||||
module.exports = function (environment) {
|
||||
let ENV = {
|
||||
@@ -70,6 +70,11 @@ module.exports = function (environment) {
|
||||
|
||||
// Notification timeout should be 0 for fast tests
|
||||
ENV.notifyTimeout = 0;
|
||||
|
||||
// Use in-memory storage
|
||||
ENV.storage = {
|
||||
memory: true
|
||||
};
|
||||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
|
||||
@@ -62,9 +62,9 @@ module('Acceptance | authentication', function (hooks) {
|
||||
};
|
||||
|
||||
const setDefaultOrigin = (test) => {
|
||||
const origin = window.location.origin;
|
||||
const session = test.owner.lookup('service:session');
|
||||
session.set('data.origin', origin);
|
||||
const windowOrigin = window.location.origin;
|
||||
const origin = test.owner.lookup('service:origin');
|
||||
origin.rendererOrigin = windowOrigin;
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
|
||||
@@ -60,9 +60,9 @@ module('Acceptance | projects', function (hooks) {
|
||||
};
|
||||
|
||||
const setDefaultOrigin = (test) => {
|
||||
const origin = window.location.origin;
|
||||
const session = test.owner.lookup('service:session');
|
||||
session.set('data.origin', origin);
|
||||
const windowOrigin = window.location.origin;
|
||||
const origin = test.owner.lookup('service:origin');
|
||||
origin.rendererOrigin = windowOrigin;
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -102,7 +102,7 @@ module('Acceptance | projects', function (hooks) {
|
||||
urls.authenticate.global = `${urls.scopes.global}/authenticate`;
|
||||
urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`;
|
||||
urls.projects = `${urls.scopes.org}/projects`;
|
||||
|
||||
|
||||
class MockIPC {
|
||||
origin = null;
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ module('Acceptance | targets', function (hooks) {
|
||||
};
|
||||
|
||||
const setDefaultOrigin = (test) => {
|
||||
const origin = window.location.origin;
|
||||
const session = test.owner.lookup('service:session');
|
||||
session.set('data.origin', origin);
|
||||
const windowOrigin = window.location.origin;
|
||||
const origin = test.owner.lookup('service:origin');
|
||||
origin.rendererOrigin = windowOrigin;
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -104,7 +104,7 @@ module('Acceptance | targets', function (hooks) {
|
||||
urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`;
|
||||
urls.projects = `${urls.scopes.org}/projects`;
|
||||
urls.targets = `${urls.projects}/targets`;
|
||||
|
||||
|
||||
class MockIPC {
|
||||
origin = null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user