Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiion committed Jun 20, 2024
1 parent 306f8c3 commit 99102b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 12 additions & 2 deletions apps/exhibition-live/components/google/GoogleOAuth.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -40,6 +41,15 @@ export const Login: FC<LoginProps> = ({ scopes }) => {
},
});

const granted = useMemo(
() =>
typeof window !== "undefined" &&
hasGrantedAnyScopeGoogle(
credentials,
...(scopes as [string, string, string]),
),
[credentials, scopes],
);
useEffect(() => {
console.log({ credentials });
if (credentials?.access_token) {
Expand All @@ -51,7 +61,7 @@ export const Login: FC<LoginProps> = ({ scopes }) => {
const logout = useCallback(() => {
clear();
}, [clear]);
return credentials?.access_token ? (
return credentials?.access_token && granted ? (
<>
<Button onClick={() => logout()}>Log out</Button>
You have access to the users drive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const NiceMappingConfigurationDialog = NiceModal.create(
return undefined;
}, [fields, newRawMapping]);

const mappedExamples = useMemo(() => {});

const handleMappingEditChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
Expand Down
9 changes: 5 additions & 4 deletions apps/exhibition-live/components/importExport/ImportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down

0 comments on commit 99102b9

Please sign in to comment.