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 = () => ({
|
||||
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"
|
||||
},
|
||||
bodyshop: null,
|
||||
fingerprint: null,
|
||||
error: null,
|
||||
conflict: false,
|
||||
};
|
||||
|
||||
const userReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case UserActionTypes.SET_LOCAL_FINGERPRINT:
|
||||
return { ...state, fingerprint: action.payload };
|
||||
case UserActionTypes.SET_INSTANCE_ID:
|
||||
return { ...state, conflict: false };
|
||||
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 { firestore } from "../../firebase/firebase.utils";
|
||||
import Fingerprint2 from "fingerprintjs2";
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
updateUserDetailsSuccess,
|
||||
setInstanceId,
|
||||
checkInstanceId,
|
||||
setLocalFingerprint,
|
||||
setInstanceConflict,
|
||||
} from "./user.actions";
|
||||
import UserActionTypes from "./user.types";
|
||||
@@ -109,6 +110,7 @@ export function* setInstanceIdSaga({ payload: uid }) {
|
||||
fingerprint,
|
||||
});
|
||||
|
||||
yield put(setLocalFingerprint(fingerprint));
|
||||
yield delay(5000);
|
||||
yield put(checkInstanceId(uid));
|
||||
} catch (error) {
|
||||
@@ -125,12 +127,8 @@ export function* checkInstanceIdSaga({ payload: uid }) {
|
||||
try {
|
||||
const userInstanceRef = firestore.doc(`userInstance/${uid}`);
|
||||
|
||||
const fingerprint = Fingerprint2.x64hash128(
|
||||
(yield Fingerprint2.getPromise({})).map((c) => c.value).join(""),
|
||||
31
|
||||
);
|
||||
|
||||
const snapshot = yield userInstanceRef.get();
|
||||
let fingerprint = yield select((state) => state.user.fingerprint);
|
||||
|
||||
if (snapshot.data().fingerprint === fingerprint) {
|
||||
yield delay(30000);
|
||||
@@ -139,13 +137,8 @@ export function* checkInstanceIdSaga({ payload: uid }) {
|
||||
console.log("ERROR: Fingerprints do not match. Conflict detected.");
|
||||
yield put(setInstanceConflict());
|
||||
}
|
||||
// yield userInstanceRef.set({
|
||||
// timestamp: new Date(),
|
||||
// fingerprint,
|
||||
// });
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
//yield put(signOutFailure(error.message));
|
||||
//TODO error handling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ const UserActionTypes = {
|
||||
SET_SHOP_DETAILS: "SET_SHOP_DETAILS",
|
||||
SET_INSTANCE_ID: "SET_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;
|
||||
|
||||
Reference in New Issue
Block a user