add check for getData reponse to be null

This commit is contained in:
Abhinav-grd 2021-01-20 08:40:00 +05:30
parent 63b26baa01
commit 78f4cca807
2 changed files with 5 additions and 3 deletions

View file

@ -19,7 +19,7 @@ function CollectionSelector({
const [encryptionKey, setEncryptionKey] = useState(null);
useEffect(() => {
(async () => {
setToken(getData(LS_KEYS.USER).token);
setToken(getData(LS_KEYS.USER)?.token);
setEncryptionKey(await getActualKey());
})();
});

View file

@ -6,9 +6,11 @@ const CryptoWorker: any = typeof window !== 'undefined'
&& Comlink.wrap(new Worker("worker/crypto.worker.js", { type: 'module' }));
export const getActualKey = async () => {
const cryptoWorker = await new CryptoWorker();
const encryptedKey = getKey(SESSION_KEYS.ENCRYPTION_KEY).encryptionKey;
const session = getData(LS_KEYS.SESSION);
if (session == null)
return;
const cryptoWorker = await new CryptoWorker();
const encryptedKey = getKey(SESSION_KEYS.ENCRYPTION_KEY)?.encryptionKey;
const key: string = await cryptoWorker.decryptB64(encryptedKey, session.sessionNonce, session.sessionKey);
return key;
}