Skip to content

Commit

Permalink
Not authorized polish
Browse files Browse the repository at this point in the history
  • Loading branch information
auniverseaway committed Sep 1, 2024
1 parent ad0cbda commit be3821a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion blocks/edit/da-title/da-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class DaTitle extends LitElement {
</div>
<div class="da-title-collab-actions-wrapper">
${this.collabStatus ? this.renderCollab() : nothing}
${this._status ? html`<p class="da-title-error-details">${this._status.message} ${this._status.action}. (${this._status.status})</p>` : nothing}
${this._status ? html`<p class="da-title-error-details">${this._status.message} ${this._status.action}.</p>` : nothing}
<div class="da-title-actions${this._actionsVis ? ' is-open' : ''}">
${this.details.view === 'config' ? this.renderSave() : this.renderAemActions()}
<button
Expand Down
6 changes: 4 additions & 2 deletions blocks/edit/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ export async function saveToAem(path, action) {
const resp = await daFetch(url, { method: 'POST' });
// eslint-disable-next-line no-console
if (!resp.ok) {
const { status } = resp;
const message = [401, 403].some((s) => s === status) ? 'Not authorized to' : 'Error during';
return {
error: {
status: resp.status,
status,
type: 'error',
message: 'Error during',
message,
},
};
}
Expand Down
20 changes: 12 additions & 8 deletions blocks/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { DA_ORIGIN } from './constants.js';

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

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

let imsDetails;

Expand All @@ -28,14 +30,16 @@ export const daFetch = async (url, opts = {}) => {
}
const resp = await fetch(url, opts);
if (resp.status === 401) {
if (accessToken) {
window.location = `${window.location.origin}/not-found`;
return { ok: false };
// Only attempt sign-in if the request is for DA.
if (DA_ORIGINS.some((origin) => url.startsWith(origin))) {
if (accessToken) {
window.location = `${window.location.origin}/not-found`;
return { ok: false };
}
const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`);
await loadIms();
handleSignIn();
}

const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`);
await loadIms();
handleSignIn();
}
return resp;
};
Expand Down

0 comments on commit be3821a

Please sign in to comment.