Skip to content

Commit

Permalink
fix: firebase setter
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimNikalayeu committed Mar 10, 2024
1 parent 9586739 commit 771dcf4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import firebaseConfig from './firebase-config.js';
import {initializeApp} from 'firebase/app';
import { getDatabase, ref, get, set } from 'firebase/database';
import { getDatabase, ref, get, set, push, update } from 'firebase/database';

const app = initializeApp(firebaseConfig);

Expand Down Expand Up @@ -39,17 +39,24 @@ export const addUser = async (clientId) => {
snapshot.forEach((childSnapshot) => {
const childData = childSnapshot.val();
if (childData.clientId === clientId) {
set(ref(db, `yandexUsers/${childSnapshot.key}`), {
clientId: clientId,
timestamp: Date.now()
});

update(usersRef, {
[childSnapshot.key]: {
clientId: clientId,
timestamp: Date.now()
}

})
isUpdated = true;
}
});
}

if (!isUpdated) {
await set(usersRef, {

console.log('pushing new user to firebase')

await push(usersRef, {
clientId: clientId,
timestamp: Date.now()
});
Expand Down

0 comments on commit 771dcf4

Please sign in to comment.