Set fingerprint locally to avoid webgl rerenders + mem leaks BOD-132
This commit is contained in:
@@ -67,3 +67,8 @@ export const checkInstanceId = (uid) => ({
|
|||||||
export const setInstanceConflict = () => ({
|
export const setInstanceConflict = () => ({
|
||||||
type: UserActionTypes.SET_INSTANCE_CONFLICT,
|
type: UserActionTypes.SET_INSTANCE_CONFLICT,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const setLocalFingerprint = (fingerprint) => ({
|
||||||
|
type: UserActionTypes.SET_LOCAL_FINGERPRINT,
|
||||||
|
payload: fingerprint,
|
||||||
|
});
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ const INITIAL_STATE = {
|
|||||||
//language: "en-US"
|
//language: "en-US"
|
||||||
},
|
},
|
||||||
bodyshop: null,
|
bodyshop: null,
|
||||||
|
fingerprint: null,
|
||||||
error: null,
|
error: null,
|
||||||
conflict: false,
|
conflict: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const userReducer = (state = INITIAL_STATE, action) => {
|
const userReducer = (state = INITIAL_STATE, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case UserActionTypes.SET_LOCAL_FINGERPRINT:
|
||||||
|
return { ...state, fingerprint: action.payload };
|
||||||
case UserActionTypes.SET_INSTANCE_ID:
|
case UserActionTypes.SET_INSTANCE_ID:
|
||||||
return { ...state, conflict: false };
|
return { ...state, conflict: false };
|
||||||
case UserActionTypes.SET_INSTANCE_CONFLICT:
|
case UserActionTypes.SET_INSTANCE_CONFLICT:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { all, call, put, takeLatest, delay } from "redux-saga/effects";
|
import { all, call, put, takeLatest, delay, select } from "redux-saga/effects";
|
||||||
import LogRocket from "logrocket";
|
import LogRocket from "logrocket";
|
||||||
import { firestore } from "../../firebase/firebase.utils";
|
import { firestore } from "../../firebase/firebase.utils";
|
||||||
import Fingerprint2 from "fingerprintjs2";
|
import Fingerprint2 from "fingerprintjs2";
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
updateUserDetailsSuccess,
|
updateUserDetailsSuccess,
|
||||||
setInstanceId,
|
setInstanceId,
|
||||||
checkInstanceId,
|
checkInstanceId,
|
||||||
|
setLocalFingerprint,
|
||||||
setInstanceConflict,
|
setInstanceConflict,
|
||||||
} from "./user.actions";
|
} from "./user.actions";
|
||||||
import UserActionTypes from "./user.types";
|
import UserActionTypes from "./user.types";
|
||||||
@@ -109,6 +110,7 @@ export function* setInstanceIdSaga({ payload: uid }) {
|
|||||||
fingerprint,
|
fingerprint,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
yield put(setLocalFingerprint(fingerprint));
|
||||||
yield delay(5000);
|
yield delay(5000);
|
||||||
yield put(checkInstanceId(uid));
|
yield put(checkInstanceId(uid));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -125,12 +127,8 @@ export function* checkInstanceIdSaga({ payload: uid }) {
|
|||||||
try {
|
try {
|
||||||
const userInstanceRef = firestore.doc(`userInstance/${uid}`);
|
const userInstanceRef = firestore.doc(`userInstance/${uid}`);
|
||||||
|
|
||||||
const fingerprint = Fingerprint2.x64hash128(
|
|
||||||
(yield Fingerprint2.getPromise({})).map((c) => c.value).join(""),
|
|
||||||
31
|
|
||||||
);
|
|
||||||
|
|
||||||
const snapshot = yield userInstanceRef.get();
|
const snapshot = yield userInstanceRef.get();
|
||||||
|
let fingerprint = yield select((state) => state.user.fingerprint);
|
||||||
|
|
||||||
if (snapshot.data().fingerprint === fingerprint) {
|
if (snapshot.data().fingerprint === fingerprint) {
|
||||||
yield delay(30000);
|
yield delay(30000);
|
||||||
@@ -139,13 +137,8 @@ export function* checkInstanceIdSaga({ payload: uid }) {
|
|||||||
console.log("ERROR: Fingerprints do not match. Conflict detected.");
|
console.log("ERROR: Fingerprints do not match. Conflict detected.");
|
||||||
yield put(setInstanceConflict());
|
yield put(setInstanceConflict());
|
||||||
}
|
}
|
||||||
// yield userInstanceRef.set({
|
|
||||||
// timestamp: new Date(),
|
|
||||||
// fingerprint,
|
|
||||||
// });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error", error);
|
console.log("error", error);
|
||||||
//yield put(signOutFailure(error.message));
|
|
||||||
//TODO error handling
|
//TODO error handling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const UserActionTypes = {
|
|||||||
SET_SHOP_DETAILS: "SET_SHOP_DETAILS",
|
SET_SHOP_DETAILS: "SET_SHOP_DETAILS",
|
||||||
SET_INSTANCE_ID: "SET_INSTANCE_ID",
|
SET_INSTANCE_ID: "SET_INSTANCE_ID",
|
||||||
CHECK_INSTANCE_ID: "CHECK_INSTANCE_ID",
|
CHECK_INSTANCE_ID: "CHECK_INSTANCE_ID",
|
||||||
SET_INSTANCE_CONFLICT: "SET_INSTANCE_CONFLICT"
|
SET_INSTANCE_CONFLICT: "SET_INSTANCE_CONFLICT",
|
||||||
|
SET_LOCAL_FINGERPRINT: "SET_LOCAL_FINGERPRINT"
|
||||||
};
|
};
|
||||||
export default UserActionTypes;
|
export default UserActionTypes;
|
||||||
|
|||||||
Reference in New Issue
Block a user