You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-24Lines changed: 28 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,10 @@ Firestack makes using the latest [Firebase](http://firebase.com) straight-forwar
6
6
7
7
Firestack is a _light-weight_ layer sitting atop the native Firebase libraries for iOS and Android (coming soon), deferring to as much of the JavaScript library as possible. For parts of the api that are natively supported by the Firebase JavaScript api, this library acts as a thin proxy to the JS objects, while it provides a native shim to those that are not covered.
8
8
9
+
## Why?
10
+
11
+
Firebase is awesome and it's combination with the Google Cloud Platform makes it super awesome. Sadly, the latest version of Firebase requires the `window` object. That's where Firestack comes in! Firestack provides a really thin layer that sits on top of the native Firebase SDKs and attempts to use the JavaScript library as much as possible rather than reinventing the wheel.
12
+
9
13
## Installing
10
14
11
15
Install the `npm` package with:
@@ -88,8 +92,8 @@ import Firestack from 'react-native-firestack'
88
92
We need to tell the Firebase library we want to _configure_ the project. Firestack provides a way to configure both the native and the JavaScript side of the project at the same time with a single command:
89
93
90
94
```javascript
91
-
constserver=newFirestack();
92
-
server.configure()
95
+
constfirestack=newFirestack();
96
+
firestack.configure()
93
97
.then(() =>console.log("Project configured and ready to boot"));
94
98
```
95
99
@@ -106,7 +110,7 @@ Firestack handles authentication for us out of the box, both with email/password
106
110
Firebase gives us a reactive method for listening for authentication. That is we can set up a listener to call a method when the user logs in and out. To set up the listener, call the `listenForAuth()` method:
We can remove this listener by calling the `unlistenForAuth()` method. This is important to release resources from our app when we don't need to hold on to the listener any longer.
128
132
129
133
```javascript
130
-
server.unlistenForAuth()
134
+
firestack.unlistenForAuth()
131
135
```
132
136
133
137
#### createUserWithEmail()
134
138
135
139
We can create a user by calling the `createUserWithEmail()` function. The `createUserWithEmail()` accepts two parameters, an email and a password.
We can update the current user's password using the `updateUserPassword()` method. It accepts a single parameter: the new password for the current user
To send a password reset for a user based upon their email, we can call the `sendPasswordResetWithEmail()` method. It accepts a single parameter: the email of the user to send a reset email.
.then(res=>console.log('Check your inbox for further instructions'))
251
255
.catch(err=>console.error('There was an error :('))
252
256
```
@@ -260,7 +264,7 @@ It accepts a single parameter:
260
264
* object which contains updated key/values for the user's profile. Possible keys are listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile).
261
265
262
266
```javascript
263
-
server.updateUserProfile({
267
+
firestack.updateUserProfile({
264
268
displayName:'Ari Lerner'
265
269
})
266
270
.then(res=>console.log('Your profile has been updated'))
@@ -272,7 +276,7 @@ server.updateUserProfile({
272
276
It's possible to delete a user completely from your account on Firebase. Calling the `deleteUser()` method will take care of this for you.
273
277
274
278
```javascript
275
-
server.deleteUser()
279
+
firestack.deleteUser()
276
280
.then(res=>console.log('Sad to see you go'))
277
281
.catch(err=>console.error('There was an error - Now you are trapped!'))
278
282
```
@@ -282,7 +286,7 @@ server.deleteUser()
282
286
To sign the current user out, use the `signOut()` method. It accepts no parameters
283
287
284
288
```javascript
285
-
server.signOut()
289
+
firestack.signOut()
286
290
.then(res=>console.log('You have been signed out'))
Although you _can_ get the current user using the `getCurrentUser()` method, it's better to use this from within the callback function provided by `listenForAuth()`. However, if you need to get the current user, call the `getCurrentUser()` method:
293
297
294
298
```javascript
295
-
server.getCurrentUser()
299
+
firestack.getCurrentUser()
296
300
.then(user=>console.log('The currently logged in user', user))
297
301
.catch(err=>console.error('An error occurred'))
298
302
```
@@ -304,7 +308,7 @@ Wouldn't it be nice to send analytics about your app usage from your users? Well
304
308
#### logEventWithName()
305
309
306
310
```javascript
307
-
server.logEventWithName("launch", {
311
+
firestack.logEventWithName("launch", {
308
312
'screen':'Main screen'
309
313
})
310
314
.then(res=>console.log('Sent event named launch'))
@@ -324,7 +328,7 @@ In order to store anything on Firebase, we need to set the storage url provided
324
328
The `setStorageUrl()` method accepts a single parameter: your root storage url.
We can upload a file using the `uploadFile()` method. Using the `uploadFile()` method, we can set the name of the destination file, the path where we want to store it, as well as any metadata along with the file.
To retrieve a stored file, we can get the url to download it from using the `storage` attribute. This method allows us to call right through to the native JavaScript object provided by the Firebase library:
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.
377
381
378
382
```javascript
379
-
server.database
383
+
firestack.database
380
384
.ref(LIST_KEY)
381
385
.orderByChild('timestamp')
382
386
.on('value', snapshot=> {
@@ -391,7 +395,7 @@ server.database
391
395
Firebase provides some static values based upon the server. We can use the `ServerValue` constant to retrieve these. For instance, to grab the TIMESTAMP on the server, use the `TIMESTAMP` value:
0 commit comments