Merge pull request #42 from ente-io/fix-403-on-new-login
Fix 403 on login
This commit is contained in:
commit
6aa29aa543
|
@ -11,9 +11,7 @@ function ConfirmLogout({ logout, ...props }) {
|
|||
centered
|
||||
>
|
||||
<Modal.Body style={{ padding: '24px' }}>
|
||||
<Modal.Title
|
||||
id="contained-modal-title-vcenter"
|
||||
>
|
||||
<Modal.Title id="contained-modal-title-vcenter">
|
||||
{constants.LOGOUT_WARNING}
|
||||
</Modal.Title>
|
||||
</Modal.Body>
|
||||
|
|
|
@ -17,10 +17,6 @@ interface Props {
|
|||
}
|
||||
export default function Sidebar(props: Props) {
|
||||
const [logoutModalView, setLogoutModalView] = useState(false);
|
||||
const [
|
||||
changeDisabledMessageModalView,
|
||||
setChangeDisabledMessageModalView,
|
||||
] = useState(false);
|
||||
function showLogoutModal() {
|
||||
setLogoutModalView(true);
|
||||
}
|
||||
|
@ -50,7 +46,8 @@ export default function Sidebar(props: Props) {
|
|||
};
|
||||
|
||||
function openFeedbackURL() {
|
||||
const feedbackURL: string = getEndpoint() + "/users/feedback?token=" + getToken();
|
||||
const feedbackURL: string =
|
||||
getEndpoint() + '/users/feedback?token=' + getToken();
|
||||
var win = window.open(feedbackURL, '_blank');
|
||||
win.focus();
|
||||
}
|
||||
|
@ -62,15 +59,23 @@ export default function Sidebar(props: Props) {
|
|||
itemListElement="div"
|
||||
>
|
||||
<div style={{ outline: 'none' }}>
|
||||
<h5 style={{ marginBottom: '12px' }}>{constants.SUBSCRIPTION_PLAN}</h5>
|
||||
<h5 style={{ marginBottom: '12px' }}>
|
||||
{constants.SUBSCRIPTION_PLAN}
|
||||
</h5>
|
||||
<div style={{ color: '#959595' }}>
|
||||
{
|
||||
subscription?.productID == "free" ? constants.FREE_SUBSCRIPTION_INFO(subscription?.expiryTime) : constants.PAID_SUBSCRIPTION_INFO(subscription?.expiryTime)
|
||||
}
|
||||
{subscription?.productID == 'free'
|
||||
? constants.FREE_SUBSCRIPTION_INFO(
|
||||
subscription?.expiryTime
|
||||
)
|
||||
: constants.PAID_SUBSCRIPTION_INFO(
|
||||
subscription?.expiryTime
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ outline: 'none', marginTop: '30px' }}>
|
||||
<h5 style={{ marginBottom: '12px' }}>{constants.USAGE_DETAILS}</h5>
|
||||
<h5 style={{ marginBottom: '12px' }}>
|
||||
{constants.USAGE_DETAILS}
|
||||
</h5>
|
||||
<div style={{ color: '#959595' }}>
|
||||
{usage ? (
|
||||
constants.USAGE_INFO(
|
||||
|
@ -88,12 +93,25 @@ export default function Sidebar(props: Props) {
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ height: '1px', marginTop: '40px', background: '#242424', width: '100%' }}></div>
|
||||
<h5 style={{ cursor: 'pointer', marginTop: '40px' }} onClick={openFeedbackURL}>
|
||||
<div
|
||||
style={{
|
||||
height: '1px',
|
||||
marginTop: '40px',
|
||||
background: '#242424',
|
||||
width: '100%',
|
||||
}}
|
||||
></div>
|
||||
<h5
|
||||
style={{ cursor: 'pointer', marginTop: '40px' }}
|
||||
onClick={openFeedbackURL}
|
||||
>
|
||||
request feature
|
||||
</h5>
|
||||
<h5 style={{ cursor: 'pointer', marginTop: '30px' }}>
|
||||
<a href="mailto:contact@ente.io" style={{ textDecoration: 'inherit', color: 'inherit' }}>
|
||||
<a
|
||||
href="mailto:contact@ente.io"
|
||||
style={{ textDecoration: 'inherit', color: 'inherit' }}
|
||||
>
|
||||
support
|
||||
</a>
|
||||
</h5>
|
||||
|
@ -103,7 +121,14 @@ export default function Sidebar(props: Props) {
|
|||
onHide={closeLogoutModal}
|
||||
logout={logout}
|
||||
/>
|
||||
<h5 style={{ cursor: 'pointer', color: '#F96C6C', marginTop: '30px' }} onClick={showLogoutModal}>
|
||||
<h5
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
color: '#F96C6C',
|
||||
marginTop: '30px',
|
||||
}}
|
||||
onClick={showLogoutModal}
|
||||
>
|
||||
logout
|
||||
</h5>
|
||||
</>
|
||||
|
|
|
@ -257,7 +257,7 @@ export default function App({ Component, pageProps, err }) {
|
|||
uploadModalView={uploadModalView}
|
||||
showUploadModal={showUploadModal}
|
||||
closeUploadModal={closeUploadModal}
|
||||
setUploadButtonView={setNavbarIconView}
|
||||
setNavbarIconView={setNavbarIconView}
|
||||
err={err}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -48,7 +48,6 @@ export default function PreviewCard(props: IProps) {
|
|||
useEffect(() => {
|
||||
if (data && !data.msrc) {
|
||||
const main = async () => {
|
||||
const token = getToken();
|
||||
const url = await DownloadManager.getPreview(data);
|
||||
setImgSrc(url);
|
||||
data.msrc = url;
|
||||
|
|
|
@ -110,7 +110,15 @@ const DateContainer = styled.div`
|
|||
padding-top: 15px;
|
||||
`;
|
||||
|
||||
export default function Gallery(props) {
|
||||
interface Props {
|
||||
openFileUploader;
|
||||
acceptedFiles;
|
||||
uploadModalView;
|
||||
closeUploadModal;
|
||||
setNavbarIconView;
|
||||
err;
|
||||
}
|
||||
export default function Gallery(props: Props) {
|
||||
const router = useRouter();
|
||||
const [collections, setCollections] = useState<collection[]>([]);
|
||||
const [
|
||||
|
@ -151,20 +159,18 @@ export default function Gallery(props) {
|
|||
const favItemIds = await getFavItemIds(data);
|
||||
setFavItemIds(favItemIds);
|
||||
|
||||
loadingBar.current.continuousStart();
|
||||
loadingBar.current?.continuousStart();
|
||||
await syncWithRemote();
|
||||
loadingBar.current.complete();
|
||||
loadingBar.current?.complete();
|
||||
setIsFirstLoad(false);
|
||||
};
|
||||
main();
|
||||
props.setUploadButtonView(true);
|
||||
props.setNavbarIconView(true);
|
||||
}, []);
|
||||
|
||||
const syncWithRemote = async () => {
|
||||
const token = getToken();
|
||||
const encryptionKey = await getActualKey();
|
||||
const collections = await syncCollections(token, encryptionKey);
|
||||
const { data, isUpdated } = await syncData(token, collections);
|
||||
const collections = await syncCollections();
|
||||
const { data, isUpdated } = await syncData(collections);
|
||||
const nonEmptyCollections = getNonEmptyCollections(collections, data);
|
||||
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
|
||||
nonEmptyCollections,
|
||||
|
@ -178,7 +184,6 @@ export default function Gallery(props) {
|
|||
setCollectionAndItsLatestFile(collectionAndItsLatestFile);
|
||||
setFavItemIds(favItemIds);
|
||||
setSinceTime(new Date().getTime());
|
||||
props.setUploadButtonView(true);
|
||||
};
|
||||
|
||||
const updateUrl = (index: number) => (url: string) => {
|
||||
|
|
|
@ -9,7 +9,12 @@ import { LS_KEYS, getData, setData } from 'utils/storage/localStorage';
|
|||
import { useRouter } from 'next/router';
|
||||
import { Formik, FormikHelpers } from 'formik';
|
||||
import * as Yup from 'yup';
|
||||
import { verifyOtt, getOtt, logoutUser } from 'services/userService';
|
||||
import {
|
||||
verifyOtt,
|
||||
getOtt,
|
||||
logoutUser,
|
||||
clearFiles,
|
||||
} from 'services/userService';
|
||||
|
||||
const Image = styled.img`
|
||||
width: 350px;
|
||||
|
@ -53,8 +58,10 @@ export default function Verify() {
|
|||
token: resp.data.token,
|
||||
id: resp.data.id,
|
||||
});
|
||||
setData(LS_KEYS.KEY_ATTRIBUTES, resp.data.keyAttributes);
|
||||
setData(LS_KEYS.SUBSCRIPTION, resp.data.subscription);
|
||||
const { subscription, keyAttributes } = resp.data;
|
||||
keyAttributes && setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);
|
||||
subscription && setData(LS_KEYS.SUBSCRIPTION, subscription);
|
||||
clearFiles();
|
||||
if (resp.data.keyAttributes?.encryptedKey) {
|
||||
router.push('/credentials');
|
||||
} else {
|
||||
|
|
|
@ -118,11 +118,16 @@ export const getCollectionUpdationTime = async (): Promise<number> => {
|
|||
return (await localForage.getItem<number>(COLLECTION_UPDATION_TIME)) ?? 0;
|
||||
};
|
||||
|
||||
export const syncCollections = async (token: string, key: string) => {
|
||||
export const syncCollections = async () => {
|
||||
const localCollections = await getLocalCollections();
|
||||
const lastCollectionUpdationTime = await getCollectionUpdationTime();
|
||||
const key = await getActualKey(),
|
||||
token = getToken();
|
||||
if (!token) {
|
||||
return localCollections;
|
||||
}
|
||||
const updatedCollections =
|
||||
(await getCollections(token, lastCollectionUpdationTime, key)) || [];
|
||||
(await getCollections(token, lastCollectionUpdationTime, key)) ?? [];
|
||||
if (updatedCollections.length == 0) {
|
||||
return localCollections;
|
||||
}
|
||||
|
@ -170,7 +175,7 @@ export const getCollectionAndItsLatestFile = (
|
|||
}
|
||||
});
|
||||
let allCollectionAndItsLatestFile: CollectionAndItsLatestFile[] = [];
|
||||
const userID = getData(LS_KEYS.USER).id;
|
||||
const userID = getData(LS_KEYS.USER)?.id;
|
||||
|
||||
for (const collection of collections) {
|
||||
if (
|
||||
|
|
|
@ -14,6 +14,10 @@ class DownloadManager {
|
|||
|
||||
public async getPreview(file: file) {
|
||||
try {
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
const cache = await caches.open('thumbs');
|
||||
const cacheResp: Response = await cache.match(file.id.toString());
|
||||
if (cacheResp) {
|
||||
|
@ -24,7 +28,7 @@ class DownloadManager {
|
|||
const resp = await HTTPService.get(
|
||||
getThumbnailUrl(file.id),
|
||||
null,
|
||||
{ 'X-Auth-Token': getToken() },
|
||||
{ 'X-Auth-Token': token },
|
||||
{ responseType: 'arraybuffer' }
|
||||
);
|
||||
const worker = await new CryptoWorker();
|
||||
|
@ -68,11 +72,15 @@ class DownloadManager {
|
|||
|
||||
private async downloadFile(file: file) {
|
||||
const worker = await new CryptoWorker();
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
if (file.metadata.fileType === 0) {
|
||||
const resp = await HTTPService.get(
|
||||
getFileUrl(file.id),
|
||||
null,
|
||||
{ 'X-Auth-Token': getToken() },
|
||||
{ 'X-Auth-Token': token },
|
||||
{ responseType: 'arraybuffer' }
|
||||
);
|
||||
const decrypted: any = await worker.decryptFile(
|
||||
|
@ -89,7 +97,7 @@ class DownloadManager {
|
|||
} else {
|
||||
const resp = await fetch(getFileUrl(file.id), {
|
||||
headers: {
|
||||
'X-Auth-Token': getToken(),
|
||||
'X-Auth-Token': token,
|
||||
},
|
||||
});
|
||||
const reader = resp.body.getReader();
|
||||
|
|
|
@ -5,6 +5,7 @@ import localForage from 'utils/storage/localForage';
|
|||
import { collection } from './collectionService';
|
||||
import { DataStream, MetadataObject } from './uploadService';
|
||||
import CryptoWorker from 'utils/crypto/cryptoWorker';
|
||||
import { getToken } from 'utils/common/key';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
const DIFF_LIMIT: number = 2500;
|
||||
|
@ -36,8 +37,8 @@ export interface file {
|
|||
updationTime: number;
|
||||
}
|
||||
|
||||
export const syncData = async (token, collections) => {
|
||||
const { files: resp, isUpdated } = await syncFiles(token, collections);
|
||||
export const syncData = async (collections) => {
|
||||
const { files: resp, isUpdated } = await syncFiles(collections);
|
||||
|
||||
return {
|
||||
data: resp.map((item) => ({
|
||||
|
@ -54,11 +55,14 @@ export const localFiles = async () => {
|
|||
return files;
|
||||
};
|
||||
|
||||
export const syncFiles = async (token: string, collections: collection[]) => {
|
||||
export const syncFiles = async (collections: collection[]) => {
|
||||
let files = await localFiles();
|
||||
let isUpdated = false;
|
||||
files = await removeDeletedCollectionFiles(collections, files);
|
||||
for (let collection of collections) {
|
||||
if (!getToken()) {
|
||||
continue;
|
||||
}
|
||||
const lastSyncTime =
|
||||
(await localForage.getItem<number>(`${collection.id}-time`)) ?? 0;
|
||||
if (collection.updationTime === lastSyncTime) {
|
||||
|
@ -66,7 +70,7 @@ export const syncFiles = async (token: string, collections: collection[]) => {
|
|||
}
|
||||
isUpdated = true;
|
||||
let fetchedFiles =
|
||||
(await getFiles(collection, lastSyncTime, DIFF_LIMIT, token)) ?? [];
|
||||
(await getFiles(collection, lastSyncTime, DIFF_LIMIT)) ?? [];
|
||||
files.push(...fetchedFiles);
|
||||
var latestVersionFiles = new Map<number, file>();
|
||||
files.forEach((file) => {
|
||||
|
@ -99,8 +103,7 @@ export const syncFiles = async (token: string, collections: collection[]) => {
|
|||
export const getFiles = async (
|
||||
collection: collection,
|
||||
sinceTime: number,
|
||||
limit: number,
|
||||
token: string
|
||||
limit: number
|
||||
): Promise<file[]> => {
|
||||
try {
|
||||
const worker = await new CryptoWorker();
|
||||
|
@ -111,6 +114,10 @@ export const getFiles = async (
|
|||
0;
|
||||
let resp;
|
||||
do {
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
break;
|
||||
}
|
||||
resp = await HTTPService.get(
|
||||
`${ENDPOINT}/collections/diff`,
|
||||
{
|
||||
|
|
|
@ -44,7 +44,11 @@ export const putAttributes = (
|
|||
export const logoutUser = async () => {
|
||||
clearKeys();
|
||||
clearData();
|
||||
localForage.clear();
|
||||
const cache = await caches.delete('thumbs');
|
||||
await clearFiles();
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
export const clearFiles = async () => {
|
||||
await localForage.clear();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue