fix(cloudly): invalidate expired dashboard sessions
This commit is contained in:
@@ -169,6 +169,17 @@ export class CloudlyDashboard extends DeesElement {
|
||||
this.syncAppdashView(uiState.activeView, uiState.activeSubview);
|
||||
});
|
||||
this.rxSubscriptions.push(uiSubscription);
|
||||
|
||||
const loginSubscription = appstate.loginStatePart
|
||||
.select((stateArg) => stateArg?.identity ?? null)
|
||||
.subscribe((identityArg) => {
|
||||
const hadIdentity = !!this.identity;
|
||||
this.identity = identityArg ?? null;
|
||||
if (!identityArg && hadIdentity) {
|
||||
void this.switchToLoginContent('Session expired. Please sign in again.');
|
||||
}
|
||||
});
|
||||
this.rxSubscriptions.push(loginSubscription);
|
||||
}
|
||||
|
||||
private syncAppdashView(viewSlug: string, subviewSlug: string | null): void {
|
||||
@@ -267,9 +278,16 @@ export class CloudlyDashboard extends DeesElement {
|
||||
const domtools = await this.domtoolsPromise;
|
||||
const loginState = appstate.loginStatePart.getState();
|
||||
if (loginState?.identity) {
|
||||
this.identity = loginState.identity;
|
||||
const identityValid = await appstate.validateStoredIdentity();
|
||||
const currentIdentity = appstate.loginStatePart.getState()?.identity ?? null;
|
||||
if (!identityValid || !currentIdentity) {
|
||||
await this.switchToLoginContent('Session expired. Please sign in again.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.identity = currentIdentity;
|
||||
try {
|
||||
appstate.apiClient.identity = loginState.identity;
|
||||
appstate.apiClient.identity = currentIdentity;
|
||||
if (!appstate.apiClient['typedsocketClient']) {
|
||||
await appstate.apiClient.start();
|
||||
}
|
||||
@@ -301,5 +319,34 @@ export class CloudlyDashboard extends DeesElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async logout() {}
|
||||
private async switchToLoginContent(statusMessageArg?: string) {
|
||||
const simpleLogin = this.shadowRoot?.querySelector('dees-simple-login') as any;
|
||||
if (!simpleLogin?.shadowRoot) return;
|
||||
|
||||
const loginDiv = simpleLogin.shadowRoot.querySelector('.login') as HTMLDivElement | null;
|
||||
const loginContainerDiv = simpleLogin.shadowRoot.querySelector('.loginContainer') as HTMLDivElement | null;
|
||||
const slotContainerDiv = simpleLogin.shadowRoot.querySelector('.slotContainer') as HTMLDivElement | null;
|
||||
const form = simpleLogin.shadowRoot.querySelector('dees-form') as any;
|
||||
|
||||
if (loginDiv) {
|
||||
loginDiv.style.opacity = '1';
|
||||
loginDiv.style.transform = 'translateY(0px)';
|
||||
}
|
||||
if (loginContainerDiv) {
|
||||
loginContainerDiv.style.pointerEvents = 'all';
|
||||
}
|
||||
if (slotContainerDiv) {
|
||||
slotContainerDiv.style.opacity = '0';
|
||||
slotContainerDiv.style.transform = 'translateY(20px)';
|
||||
slotContainerDiv.style.pointerEvents = 'none';
|
||||
}
|
||||
if (form && statusMessageArg) {
|
||||
form.setStatus('error', statusMessageArg);
|
||||
}
|
||||
}
|
||||
|
||||
private async logout() {
|
||||
await appstate.loginStatePart.dispatchAction(appstate.logoutAction, null);
|
||||
await this.switchToLoginContent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user