Skip to content

Commit

Permalink
Merge pull request #76 from auth0-lab/add-env-var
Browse files Browse the repository at this point in the history
adding envvar for gconn
  • Loading branch information
cristiandouce authored Oct 12, 2024
2 parents 5bdeb58 + 1cafe9b commit 2173ee6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
3 changes: 2 additions & 1 deletion components/auth0/user-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -76,7 +77,7 @@ export default function UserProfile({ user }: { user: KeyValueMap }) {
<ConnectedAccounts
availableAccounts={[
{
connection: "google-oauth2",
connection: getGoogleConnectionName(),
displayName: "Google",
api: "google-all",
description: "Create and manage events in your Google Calendar.",
Expand Down
8 changes: 5 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export const formatNumber = (value: number) =>
currency: "USD",
}).format(value);

export const runAsyncFnWithoutBlocking = (
fn: (...args: any) => Promise<any>
) => {
export const runAsyncFnWithoutBlocking = (fn: (...args: any) => Promise<any>) => {
fn();
};

export function getGoogleConnectionName() {
return process.env.NEXT_PUBLIC_GOOGLE_CONNECTION_NAME || "google-oauth2";
}
21 changes: 6 additions & 15 deletions sdk/auth0/3rd-party-apis/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getGoogleConnectionName } from "@/lib/utils";
import { getSession } from "@auth0/nextjs-auth0";

import * as box from "./providers/box";
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
27 changes: 16 additions & 11 deletions sdk/components/connect-google-account.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { getGoogleConnectionName } from "@/lib/utils";
import { PromptUserContainer } from "@/llm/components/prompt-user-container";

export const ConnectGoogleAccount = ({
Expand All @@ -14,16 +15,20 @@ export const ConnectGoogleAccount = ({
readOnly?: boolean;
}) => {
return (
<PromptUserContainer
title={title}
description={description}
action={{
label: "Connect",
onClick: () => {
window.location.href = `/api/auth/login?3rdPartyApi=${api}&linkWith=google-oauth2&returnTo=${window.location.pathname}`;
},
}}
readOnly={readOnly}
/>
<>
<PromptUserContainer
title={title}
description={description}
action={{
label: "Connect",
onClick: () => {
window.location.href = `/api/auth/login?3rdPartyApi=${api}&linkWith=${getGoogleConnectionName()}&returnTo=${
window.location.pathname
}`;
},
}}
readOnly={readOnly}
/>
</>
);
};

0 comments on commit 2173ee6

Please sign in to comment.