Skip to content

Commit be3821a

Browse files
committed
Not authorized polish
1 parent ad0cbda commit be3821a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

blocks/edit/da-title/da-title.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default class DaTitle extends LitElement {
147147
</div>
148148
<div class="da-title-collab-actions-wrapper">
149149
${this.collabStatus ? this.renderCollab() : nothing}
150-
${this._status ? html`<p class="da-title-error-details">${this._status.message} ${this._status.action}. (${this._status.status})</p>` : nothing}
150+
${this._status ? html`<p class="da-title-error-details">${this._status.message} ${this._status.action}.</p>` : nothing}
151151
<div class="da-title-actions${this._actionsVis ? ' is-open' : ''}">
152152
${this.details.view === 'config' ? this.renderSave() : this.renderAemActions()}
153153
<button

blocks/edit/utils/helpers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ export async function saveToAem(path, action) {
9898
const resp = await daFetch(url, { method: 'POST' });
9999
// eslint-disable-next-line no-console
100100
if (!resp.ok) {
101+
const { status } = resp;
102+
const message = [401, 403].some((s) => s === status) ? 'Not authorized to' : 'Error during';
101103
return {
102104
error: {
103-
status: resp.status,
105+
status,
104106
type: 'error',
105-
message: 'Error during',
107+
message,
106108
},
107109
};
108110
}

blocks/shared/utils.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { DA_ORIGIN } from './constants.js';
22

33
const { getNx } = await import('../../scripts/utils.js');
44

5-
const ALLOWED_TOKEN = ['https://admin.hlx.page', 'https://admin.da.live', 'https://stage-admin.da.live'];
5+
const DA_ORIGINS = ['https://admin.da.live', 'https://stage-admin.da.live'];
6+
const AEM_ORIGINS = ['https://admin.hlx.page', 'https://admin.aem.live'];
7+
const ALLOWED_TOKEN = [...DA_ORIGINS, ...AEM_ORIGINS];
68

79
let imsDetails;
810

@@ -28,14 +30,16 @@ export const daFetch = async (url, opts = {}) => {
2830
}
2931
const resp = await fetch(url, opts);
3032
if (resp.status === 401) {
31-
if (accessToken) {
32-
window.location = `${window.location.origin}/not-found`;
33-
return { ok: false };
33+
// Only attempt sign-in if the request is for DA.
34+
if (DA_ORIGINS.some((origin) => url.startsWith(origin))) {
35+
if (accessToken) {
36+
window.location = `${window.location.origin}/not-found`;
37+
return { ok: false };
38+
}
39+
const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`);
40+
await loadIms();
41+
handleSignIn();
3442
}
35-
36-
const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`);
37-
await loadIms();
38-
handleSignIn();
3943
}
4044
return resp;
4145
};

0 commit comments

Comments
 (0)