From 1cafe9bc96e78a8dd7dfbb75213b5b0343cf5cd7 Mon Sep 17 00:00:00 2001 From: jcenturion-okta Date: Fri, 11 Oct 2024 18:01:57 -0300 Subject: [PATCH] adding envvar for gconn --- components/auth0/user-profile.tsx | 3 ++- lib/utils.ts | 8 ++++--- sdk/auth0/3rd-party-apis/index.tsx | 21 +++++------------- sdk/components/connect-google-account.tsx | 27 ++++++++++++++--------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/components/auth0/user-profile.tsx b/components/auth0/user-profile.tsx index bcfc511..a52643f 100644 --- a/components/auth0/user-profile.tsx +++ b/components/auth0/user-profile.tsx @@ -7,6 +7,7 @@ import { twMerge } from "tailwind-merge"; import { buttonVariants } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import useConnectedAccounts from "@/hooks/auth0/use-connected-accounts"; +import { getGoogleConnectionName } from "@/lib/utils"; import BasicInfoForm from "./basic-info-form"; import ConnectedAccounts from "./connected-accounts"; @@ -76,7 +77,7 @@ export default function UserProfile({ user }: { user: KeyValueMap }) { currency: "USD", }).format(value); -export const runAsyncFnWithoutBlocking = ( - fn: (...args: any) => Promise -) => { +export const runAsyncFnWithoutBlocking = (fn: (...args: any) => Promise) => { fn(); }; + +export function getGoogleConnectionName() { + return process.env.NEXT_PUBLIC_GOOGLE_CONNECTION_NAME || "google-oauth2"; +} diff --git a/sdk/auth0/3rd-party-apis/index.tsx b/sdk/auth0/3rd-party-apis/index.tsx index 9ce3b1a..e69e6c3 100644 --- a/sdk/auth0/3rd-party-apis/index.tsx +++ b/sdk/auth0/3rd-party-apis/index.tsx @@ -1,3 +1,4 @@ +import { getGoogleConnectionName } from "@/lib/utils"; import { getSession } from "@auth0/nextjs-auth0"; import * as box from "./providers/box"; @@ -12,9 +13,7 @@ const PROVIDERS_APIS = [ { name: "google", api: "google-all", - requiredScopes: [ - "https://www.googleapis.com/auth/calendar.events", - ], + requiredScopes: ["https://www.googleapis.com/auth/calendar.events"], }, { name: "box", @@ -54,10 +53,7 @@ const providerMapper = { const accessToken = await google.getAccessToken(); if (accessToken) { - provider.containsRequiredScopes = await google.verifyAccessToken( - accessToken, - requiredScopes - ); + provider.containsRequiredScopes = await google.verifyAccessToken(accessToken, requiredScopes); } provider.isAPIAccessEnabled = !!accessToken; @@ -92,9 +88,7 @@ export async function getThirdPartyContext(params: With3PartyApisParams) { }; for (const provider of params.providers) { - context[provider.name] = await providerMapper[provider.name]( - provider.requiredScopes - ); + context[provider.name] = await providerMapper[provider.name](provider.requiredScopes); } return context; @@ -105,15 +99,12 @@ export async function handle3rdPartyParams(thirdPartyApi: string) { const user = session?.user; let authorizationParams = {}; - const provider = PROVIDERS_APIS.find( - (provider) => - provider.api === thirdPartyApi || provider.name === thirdPartyApi - ); + const provider = PROVIDERS_APIS.find((provider) => provider.api === thirdPartyApi || provider.name === thirdPartyApi); switch (provider?.name) { case "google": authorizationParams = { - connection: "google-oauth2", + connection: getGoogleConnectionName(), connection_scope: provider?.requiredScopes.join(), access_type: "offline", login_hint: user?.email, diff --git a/sdk/components/connect-google-account.tsx b/sdk/components/connect-google-account.tsx index fbc9efa..998a1c1 100644 --- a/sdk/components/connect-google-account.tsx +++ b/sdk/components/connect-google-account.tsx @@ -1,5 +1,6 @@ "use client"; +import { getGoogleConnectionName } from "@/lib/utils"; import { PromptUserContainer } from "@/llm/components/prompt-user-container"; export const ConnectGoogleAccount = ({ @@ -14,16 +15,20 @@ export const ConnectGoogleAccount = ({ readOnly?: boolean; }) => { return ( - { - window.location.href = `/api/auth/login?3rdPartyApi=${api}&linkWith=google-oauth2&returnTo=${window.location.pathname}`; - }, - }} - readOnly={readOnly} - /> + <> + { + window.location.href = `/api/auth/login?3rdPartyApi=${api}&linkWith=${getGoogleConnectionName()}&returnTo=${ + window.location.pathname + }`; + }, + }} + readOnly={readOnly} + /> + ); };