🛠 Fix JWT loading for shared view (#76)
* Fix JWT loading * Use a different local storage for shared view
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
export default class LocalStorage {
|
export default class LocalStorage {
|
||||||
static prefix = 'tdrive:';
|
static prefix = 'tdrive:';
|
||||||
|
|
||||||
|
//For shared views we will use another prefix
|
||||||
|
static setPrefix(prefix: string) {
|
||||||
|
LocalStorage.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
static setItem(key: string, value: unknown) {
|
static setItem(key: string, value: unknown) {
|
||||||
window.localStorage.setItem(`${LocalStorage.prefix}${key}`, JSON.stringify(value));
|
window.localStorage.setItem(`${LocalStorage.prefix}${key}`, JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ export default ({
|
|||||||
context?: EmbedContext;
|
context?: EmbedContext;
|
||||||
inPublicSharing?: boolean;
|
inPublicSharing?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
//Preload applications mainly for shared view
|
|
||||||
useCompanyApplications();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SelectorModal />
|
<SelectorModal />
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
import Avatar from '@atoms/avatar';
|
||||||
|
import A from '@atoms/link';
|
||||||
|
import { Modal, ModalContent } from '@atoms/modal';
|
||||||
|
import { Base } from '@atoms/text';
|
||||||
|
import { useCompanyApplications } from '@features/applications/hooks/use-company-applications';
|
||||||
|
import { Application } from '@features/applications/types/application';
|
||||||
import { Transition } from '@headlessui/react';
|
import { Transition } from '@headlessui/react';
|
||||||
import {
|
import {
|
||||||
ChevronLeftIcon,
|
ChevronLeftIcon,
|
||||||
@@ -6,12 +12,6 @@ import {
|
|||||||
FolderDownloadIcon,
|
FolderDownloadIcon,
|
||||||
LinkIcon,
|
LinkIcon,
|
||||||
} from '@heroicons/react/outline';
|
} from '@heroicons/react/outline';
|
||||||
import Avatar from '@atoms/avatar';
|
|
||||||
import A from '@atoms/link';
|
|
||||||
import { Modal, ModalContent } from '@atoms/modal';
|
|
||||||
import { Base } from '@atoms/text';
|
|
||||||
import { useCompanyApplications } from '@features/applications/hooks/use-company-applications';
|
|
||||||
import { Application } from '@features/applications/types/application';
|
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { atom, useRecoilState } from 'recoil';
|
import { atom, useRecoilState } from 'recoil';
|
||||||
import { slideXTransition, slideXTransitionReverted } from 'src/utils/transitions';
|
import { slideXTransition, slideXTransitionReverted } from 'src/utils/transitions';
|
||||||
|
|||||||
@@ -22,12 +22,18 @@ import {
|
|||||||
} from '../../../../features/drive/api-client/api-client';
|
} from '../../../../features/drive/api-client/api-client';
|
||||||
import useRouterCompany from '../../../../features/router/hooks/use-router-company';
|
import useRouterCompany from '../../../../features/router/hooks/use-router-company';
|
||||||
import { CreateModalWithUploadZones } from '../../side-bar/actions';
|
import { CreateModalWithUploadZones } from '../../side-bar/actions';
|
||||||
import { useRecoilState } from 'recoil';
|
import { useCompanyApplications } from 'app/features/applications/hooks/use-company-applications';
|
||||||
import { DriveCurrentFolderAtom } from './browser';
|
import LocalStorage from 'app/features/global/framework/local-storage-service';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const companyId = useRouterCompany();
|
const companyId = useRouterCompany();
|
||||||
|
|
||||||
|
//Create a different local storage for shared view
|
||||||
|
useEffect(() => {
|
||||||
|
LocalStorage.setPrefix('tdrive-shared:');
|
||||||
|
LocalStorage.clear();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [state, setState] = useState({ group: { logo: '', name: '' } });
|
const [state, setState] = useState({ group: { logo: '', name: '' } });
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const routeState = RouterService.getStateFromRoute();
|
const routeState = RouterService.getStateFromRoute();
|
||||||
@@ -97,6 +103,9 @@ const AccessChecker = ({
|
|||||||
const { details, loading, refresh } = useDriveItem(folderId);
|
const { details, loading, refresh } = useDriveItem(folderId);
|
||||||
const companyId = useRouterCompany();
|
const companyId = useRouterCompany();
|
||||||
const [password, setPassword] = useState((token || '').split('+')[1] || '');
|
const [password, setPassword] = useState((token || '').split('+')[1] || '');
|
||||||
|
const [accessGranted, setAccessGranted] = useState(false);
|
||||||
|
//Preload applications mainly for shared view
|
||||||
|
const { refresh: refreshApplications } = useCompanyApplications();
|
||||||
|
|
||||||
const setPublicToken = async (token: string, password?: string) => {
|
const setPublicToken = async (token: string, password?: string) => {
|
||||||
try {
|
try {
|
||||||
@@ -114,16 +123,21 @@ const AccessChecker = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
JWTStorage.updateJWT(access_token);
|
JWTStorage.updateJWT(access_token);
|
||||||
|
|
||||||
|
//Everything alright, load the drive
|
||||||
|
setAccessGranted(true);
|
||||||
|
refresh(folderId);
|
||||||
|
refreshApplications();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ToasterService.error('Unable to access documents: ' + e);
|
ToasterService.error('Unable to access documents: ' + e);
|
||||||
|
setAccessGranted(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
await setPublicToken(token || '');
|
await setPublicToken(token || '');
|
||||||
refresh(folderId);
|
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -131,7 +145,7 @@ const AccessChecker = ({
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!details?.item?.id && !loading) {
|
if ((!details?.item?.id && !loading) || !accessGranted) {
|
||||||
return (
|
return (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<div style={{ height: '20vh' }} />
|
<div style={{ height: '20vh' }} />
|
||||||
|
|||||||
Reference in New Issue
Block a user