diff --git a/packages/backend-core/src/configs/configs.ts b/packages/backend-core/src/configs/configs.ts index b461497747..c279babb71 100644 --- a/packages/backend-core/src/configs/configs.ts +++ b/packages/backend-core/src/configs/configs.ts @@ -32,8 +32,7 @@ export async function getConfig( const db = context.getGlobalDB() try { // await to catch error - const config = (await db.get(generateConfigID(type))) as T - return config + return (await db.get(generateConfigID(type))) as T } catch (e: any) { if (e.status === 404) { return diff --git a/packages/backend-core/src/middleware/passport/datasource/google.ts b/packages/backend-core/src/middleware/passport/datasource/google.ts index 32451cb8d2..6fd4e9ff32 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.ts +++ b/packages/backend-core/src/middleware/passport/datasource/google.ts @@ -78,17 +78,23 @@ export async function postAuth( ), { successRedirect: "/", failureRedirect: "/error" }, async (err: any, tokens: string[]) => { + const baseUrl = `/builder/app/${authStateCookie.appId}/data` // update the DB for the datasource with all the user info await doWithDB(authStateCookie.appId, async (db: Database) => { - const datasource = await db.get(authStateCookie.datasourceId) + let datasource + try { + datasource = await db.get(authStateCookie.datasourceId) + } catch (err: any) { + if (err.status === 404) { + ctx.redirect(baseUrl) + } + } if (!datasource.config) { datasource.config = {} } datasource.config.auth = { type: "google", ...tokens } await db.put(datasource) - ctx.redirect( - `/builder/app/${authStateCookie.appId}/data/datasource/${authStateCookie.datasourceId}` - ) + ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`) }) } )(ctx, next) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte index 4622bd7b19..0cf92dde2b 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte @@ -5,18 +5,28 @@ export let preAuthStep export let datasource + export let disabled $: tenantId = $auth.tenantId