Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blocks/edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function setUI(el, utils) {
}

const { daFetch } = await utils;
const { permissions } = await daFetch(details.sourceUrl, { method: 'HEAD' });
const { permissions = [] } = await daFetch(details.sourceUrl, { method: 'HEAD' });
daTitle.permissions = permissions;
daContent.permissions = permissions;

Expand Down
5 changes: 5 additions & 0 deletions blocks/edit/prose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import linkConverter from './plugins/linkConverter.js';
import sectionPasteHandler from './plugins/sectionPasteHandler.js';
import base64Uploader from './plugins/base64uploader.js';
import { COLLAB_ORIGIN, DA_ORIGIN } from '../../shared/constants.js';
import { logOut } from '../../shared/utils.js';
import toggleLibrary from '../da-library/da-library.js';
import { getLocClass } from './loc-utils.js';
import { getSchema } from './schema.js';
Expand Down Expand Up @@ -219,6 +220,10 @@ export default function initProse({ path, permissions }) {
const canWrite = permissions.some((permission) => permission === 'write');

const wsProvider = new WebsocketProvider(server, roomName, ydoc, opts);
wsProvider.on('connection-error', async () => {
await logOut();
});

addSyncedListener(wsProvider, canWrite);

createAwarenessStatusWidget(wsProvider, window);
Expand Down
13 changes: 13 additions & 0 deletions blocks/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export async function initIms() {
}
}

export async function logOut() {
imsDetails = null;
try {
const { handleSignOut } = await import(`${getNx()}/utils/ims.js`);
handleSignOut();
} catch {
// do nothing
}
window.location.reload();
}

export const daFetch = async (url, opts = {}) => {
opts.headers = opts.headers || {};
let accessToken;
Expand Down Expand Up @@ -50,6 +61,8 @@ export const daFetch = async (url, opts = {}) => {
const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`);
await loadIms();
handleSignIn();
// wait 1 second to let ims do its things
await new Promise((resolve) => { setTimeout(resolve, 1000); });
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to verify - handleSignIn will force a page redirect to ims, so this await will be cut short on page navigation?

}
}

Expand Down
Loading