From 99102b9679c518692e64c69364e4a29734fddc54 Mon Sep 17 00:00:00 2001 From: Winzlieb Date: Thu, 20 Jun 2024 13:23:43 +0200 Subject: [PATCH] fix build --- .../components/google/GoogleOAuth.tsx | 14 ++++++++++++-- .../google/NiceMappingConfigurationDialog.tsx | 2 -- .../components/importExport/ImportPage.tsx | 9 +++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/exhibition-live/components/google/GoogleOAuth.tsx b/apps/exhibition-live/components/google/GoogleOAuth.tsx index eb2d9e34..52f62eee 100644 --- a/apps/exhibition-live/components/google/GoogleOAuth.tsx +++ b/apps/exhibition-live/components/google/GoogleOAuth.tsx @@ -1,10 +1,11 @@ import { + hasGrantedAnyScopeGoogle, TokenResponse, useGoogleLogin, useGoogleOneTapLogin, } from "@react-oauth/google"; import { Button } from "@mui/material"; -import { FC, useCallback, useEffect } from "react"; +import { FC, useCallback, useEffect, useMemo } from "react"; import { useGoogleToken } from "./useGoogleToken"; type LoginProps = { @@ -40,6 +41,15 @@ export const Login: FC = ({ scopes }) => { }, }); + const granted = useMemo( + () => + typeof window !== "undefined" && + hasGrantedAnyScopeGoogle( + credentials, + ...(scopes as [string, string, string]), + ), + [credentials, scopes], + ); useEffect(() => { console.log({ credentials }); if (credentials?.access_token) { @@ -51,7 +61,7 @@ export const Login: FC = ({ scopes }) => { const logout = useCallback(() => { clear(); }, [clear]); - return credentials?.access_token ? ( + return credentials?.access_token && granted ? ( <> You have access to the users drive diff --git a/apps/exhibition-live/components/google/NiceMappingConfigurationDialog.tsx b/apps/exhibition-live/components/google/NiceMappingConfigurationDialog.tsx index fc547c7c..4f38926d 100644 --- a/apps/exhibition-live/components/google/NiceMappingConfigurationDialog.tsx +++ b/apps/exhibition-live/components/google/NiceMappingConfigurationDialog.tsx @@ -63,8 +63,6 @@ export const NiceMappingConfigurationDialog = NiceModal.create( return undefined; }, [fields, newRawMapping]); - const mappedExamples = useMemo(() => {}); - const handleMappingEditChange = ( event: React.ChangeEvent, ) => { diff --git a/apps/exhibition-live/components/importExport/ImportPage.tsx b/apps/exhibition-live/components/importExport/ImportPage.tsx index 41c4bec5..86727bc3 100644 --- a/apps/exhibition-live/components/importExport/ImportPage.tsx +++ b/apps/exhibition-live/components/importExport/ImportPage.tsx @@ -2,12 +2,12 @@ import React, { FunctionComponent, useCallback, useMemo } from "react"; import { Box, Button } from "@mui/material"; import Grid2 from "@mui/material/Unstable_Grid2"; import { Login } from "../google/GoogleOAuth"; -import { hasGrantedAnyScopeGoogle } from "@react-oauth/google"; import { useGoogleToken } from "../google/useGoogleToken"; import NiceModal from "@ebay/nice-modal-react"; import { GoogleDrivePickerModal } from "../google/GoogleDrivePicker"; import { useModifiedRouter } from "@slub/edb-state-hooks"; import { GoogleSpreadSheetContainer } from "../google/GoogleSpreadSheetContainer"; +import { hasGrantedAnyScopeGoogle } from "@react-oauth/google"; const scopes: [string, string, string] = [ "https://www.googleapis.com/auth/drive.readonly.metadata", @@ -34,9 +34,10 @@ export const ImportPage: FunctionComponent = () => { ); const hasAccess = useMemo(() => { - const hasAccess = hasGrantedAnyScopeGoogle(credentials, ...scopes); - console.log({ credentials, hasAccess }); - return Boolean(credentials) && hasAccess; + const granted = + typeof window !== "undefined" && + hasGrantedAnyScopeGoogle(credentials, ...scopes); + return Boolean(credentials) && granted; }, [credentials]); const openDrivePicker = useCallback(() => { NiceModal.show(GoogleDrivePickerModal, {}).then(