Added fingerprinting fixed + update firebase fingerprint on log in BOD-132

This commit is contained in:
Patrick Fic
2020-05-21 13:17:59 -07:00
parent 2ab2a27d27
commit 201e85d7db
9 changed files with 279 additions and 147 deletions

View File

@@ -12,6 +12,8 @@ const INITIAL_STATE = {
const userReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case UserActionTypes.SET_INSTANCE_ID:
return { ...state, conflict: false };
case UserActionTypes.SET_INSTANCE_CONFLICT:
return { ...state, conflict: true };
case UserActionTypes.SIGN_IN_SUCCESS:

View File

@@ -26,7 +26,6 @@ export function* signInWithEmail({ payload: { email, password } }) {
const { user } = yield auth.signInWithEmailAndPassword(email, password);
LogRocket.identify(user.email);
yield put(setInstanceId("123"));
yield put(
signInSuccess({
uid: user.uid,
@@ -51,7 +50,7 @@ export function* isUserAuthenticated() {
yield put(unauthorizedUser());
return;
}
yield put(setInstanceId(user.uid));
LogRocket.identify(user.email);
yield put(
signInSuccess({
@@ -101,16 +100,15 @@ export function* setInstanceIdSaga({ payload: uid }) {
const userInstanceRef = firestore.doc(`userInstance/${uid}`);
const fingerprint = Fingerprint2.x64hash128(
(yield Fingerprint2.getPromise({
excludes: { fonts: true, audio: true, webgl: true },
})).join(""),
(yield Fingerprint2.getPromise({})).map((c) => c.value).join(""),
31
);
yield userInstanceRef.set({
timestamp: new Date(),
fingerprint,
});
var result = window.confirm("Press a button!");
if (result)
yield userInstanceRef.set({
timestamp: new Date(),
fingerprint,
});
yield delay(5000);
yield put(checkInstanceId(uid));
@@ -129,22 +127,17 @@ export function* checkInstanceIdSaga({ payload: uid }) {
const userInstanceRef = firestore.doc(`userInstance/${uid}`);
const fingerprint = Fingerprint2.x64hash128(
(yield Fingerprint2.getPromise({
excludes: { fonts: true, audio: true, webgl: true },
})).join(""),
(yield Fingerprint2.getPromise({})).map((c) => c.value).join(""),
31
);
const snapshot = yield userInstanceRef.get();
console.log("function*checkInstanceIdSaga -> snapshot", snapshot.data());
console.log("fingerprint", fingerprint);
if (snapshot.data().fingerprint === fingerprint) {
console.log("Waiting and checking.");
yield delay(5000);
yield delay(30000);
yield put(checkInstanceId(uid));
} else {
console.log("Didnt match");
console.log("ERROR: Fingerprints do not match. Conflict detected.");
yield put(setInstanceConflict());
}
// yield userInstanceRef.set({
@@ -158,6 +151,14 @@ export function* checkInstanceIdSaga({ payload: uid }) {
}
}
export function* onSignInSuccess() {
yield takeLatest(UserActionTypes.SIGN_IN_SUCCESS, signInSuccessSaga);
}
export function* signInSuccessSaga({ payload }) {
yield put(setInstanceId(payload.uid));
}
export function* userSagas() {
yield all([
call(onEmailSignInStart),
@@ -166,5 +167,6 @@ export function* userSagas() {
call(onUpdateUserDetails),
call(onSetInstanceId),
call(onCheckInstanceId),
call(onSignInSuccess),
]);
}