Skip to content

Instantly share code, notes, and snippets.

@krizzu
Last active January 6, 2019 13:56
Show Gist options
  • Save krizzu/76e15c471f258c66a82fef5135677d44 to your computer and use it in GitHub Desktop.
Save krizzu/76e15c471f258c66a82fef5135677d44 to your computer and use it in GitHub Desktop.
// @flow
import firebase from 'react-native-firebase';
export const DB = firebase.firestore();
export const USER_COLLECTION = 'users'; // name of collection in Firestore
export async function createUserDataBaseEntry(userId: string) {
// creating a new transaction
return DB.runTransaction(async transaction => {
// get reference to 'users' collection, pointing to document with name of user's ID
const userDoc = DB.collection(USER_COLLECTION).doc(userId);
// create empty user
transaction.set(userDoc, {
name: null,
surname: null,
});
}).catch(e => alert('Something went wrong:', e.message));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment