SYNC: dbgate cloud redirect workflow

This commit is contained in:
SPRINX0\prochazka
2025-06-24 09:22:16 +02:00
committed by Diflow
parent bd88b8411e
commit eba16cc15d
9 changed files with 64 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ import { getConfig } from './utility/metadataLoaders';
import { isAdminPage } from './utility/pageDefs';
import getElectron from './utility/getElectron';
import { isProApp } from './utility/proTools';
import { cloudSigninTokenHolder, selectedWidget } from './stores';
export function isOauthCallback() {
const params = new URLSearchParams(location.search);
@@ -114,6 +115,12 @@ export function handleOauthCallback() {
return true;
}
const cloudSid = params.get('dbgate-cloud-sid');
if (cloudSid) {
sessionStorage.setItem('dbgate-cloud-sid', cloudSid);
internalRedirectTo(`/`);
}
return false;
}
@@ -187,6 +194,18 @@ export async function handleAuthOnStartup(config) {
}
}
async function checkDbGateCloudLogin() {
const sid = sessionStorage.getItem('dbgate-cloud-sid');
if (sid) {
const tokenHolder = await apiCall('auth/cloud-login-redirected', { sid });
if (tokenHolder) {
sessionStorage.removeItem('dbgate-cloud-sid');
cloudSigninTokenHolder.set(tokenHolder);
selectedWidget.set('cloud-private');
}
}
}
if (page == 'error') return;
if (checkConfigError()) return;
@@ -199,6 +218,7 @@ export async function handleAuthOnStartup(config) {
if (page == 'license' || page == 'admin-license') return;
if (checkTrialDaysLeft()) return;
if (checkInvalidLicense()) return;
checkDbGateCloudLogin();
// if (config.configurationError) {
// internalRedirectTo(`/error.html`);

View File

@@ -289,8 +289,8 @@ export function installNewVolatileConnectionListener() {
}
export function installNewCloudTokenListener() {
// console.log('HOLDER', tokenHolder);
apiOn('got-cloud-token', async tokenHolder => {
// console.log('HOLDER', tokenHolder);
cloudSigninTokenHolder.set(tokenHolder);
selectedWidget.set('cloud-private');
});

View File

@@ -135,8 +135,16 @@
}
async function handleOpenCloudLogin() {
const { url, sid } = await apiCall('auth/create-cloud-login-session', { client: getElectron() ? 'app' : 'web' });
openWebLink(url, true);
const useRedirect = getCurrentConfig()?.redirectToDbGateCloudLogin;
const { url, sid } = await apiCall('auth/create-cloud-login-session', {
client: getElectron() ? 'app' : 'web',
redirectUri: useRedirect ? location.origin + location.pathname : undefined,
});
if (useRedirect) {
location.href = url;
} else {
openWebLink(url, true);
}
}
</script>