Skip to content

Commit fdb89f0

Browse files
committed
Merge branch 'v3' of github.com:fullstackreact/react-native-firestack into v3
* 'v3' of github.com:fullstackreact/react-native-firestack: (30 commits) Fix possible NPE in iOS database module Create working podspec for Firestack Add error callback for database .on handler (matches Web spec) Update authentication.md auth().currentUser.reload() now correctly calls reloadUser - woops messaging.send() now only accepts an object of type RemoteMessage as defined in messaging.js - this now includes all the previously missing options such as ttl and collapse key added currentUser.reload() method - android only, needs ios Fix incorrect db path Add storage documentation misc Fix example provider name - JS: added EmailAuthProvider interface - .credential(email, password); standardise auth messages to match web sdk error messages standardise auth messages to match web sdk error messages Fix issues caused by path type change. Fix breakage when path to declare ref.on() event handler differs from paths of snapshots returned by callback. Support for ref.once('child_added') Add timeout Fix error 'TypeError: Cannot read property 'snapshot' of undefined' Wrap update function in try block. ...
2 parents 5f8aac2 + 9a84661 commit fdb89f0

20 files changed

+534
-146
lines changed

Firestack.podspec

+24-57
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,28 @@
11
require 'json'
2-
package = JSON.parse(File.read('package.json'))
3-
version = package["version"]
4-
repo = package['repository']
5-
author = package['author']
62

7-
all_pods = [
8-
'FirebaseAnalytics', 'FirebaseAuth', 'FirebaseRemoteConfig',
9-
'FirebaseDatabase', 'FirebaseStorage', 'FirebaseInstanceID',
10-
'GoogleInterchangeUtilities', 'GoogleIPhoneUtilities',
11-
'GoogleNetworkingUtilities', 'GoogleParsingUtilities',
12-
'GoogleSymbolUtilities'
13-
]
3+
package = JSON.parse(File.read('package.json'))
144

155
Pod::Spec.new do |s|
16-
17-
s.name = "Firestack"
18-
s.version = version
19-
s.summary = "Firestack makes working with Firebase v3 easy"
20-
21-
s.description = <<-DESC
22-
Wanna integrate firebase into your app using React Native?
23-
DESC
24-
25-
s.homepage = "http://fullstackreact.com"
26-
27-
s.license = { :type => "MIT", :file => "LICENSE" }
28-
s.author = { "Ari Lerner" => author }
29-
s.social_media_url = 'http://twitter.com/fullstackio'
30-
31-
# When using multiple platforms
32-
s.ios.deployment_target = "8.0"
33-
# s.osx.deployment_target = "10.7"
34-
# s.watchos.deployment_target = "2.0"
35-
# s.tvos.deployment_target = "9.0"
36-
37-
s.source = { :git => repo['url'], :tag => "v#{version}" }
38-
s.public_header_files = "ios/Firestack/*.h"
39-
40-
s.source_files = 'ios/Firestack/*.{h,m}'
41-
s.preserve_paths = 'README.md', 'package.json', '*.js'
42-
43-
s.ios.frameworks = [
44-
'CFNetwork', 'Security', 'SystemConfiguration'
45-
]
46-
s.ios.libraries = ['icucore', 'c++', 'sqlite3', 'z']
47-
48-
s.xcconfig = {
49-
'HEADER_SEARCH_PATHS' => [
50-
"$(inherited)",
51-
"${SRCROOT}/../../React/**",
52-
"${SRCROOT}/../../node_modules/react-native/**"
53-
].join(' '),
54-
'FRAMEWORK_SEARCH_PATHS' => [
55-
"$(inherited)",
56-
"${PODS_ROOT}/Firebase/**",
57-
"${PODS_ROOT}/FirebaseStorage/**",
58-
].join(' '),
59-
'OTHER_LDFLAGS' => '$(inherited) -ObjC'
60-
}
61-
end
6+
s.name = "Firestack"
7+
s.version = package["version"]
8+
s.summary = package["description"]
9+
s.description = <<-DESC
10+
Wanna integrate firebase into your app using React Native?
11+
DESC
12+
s.homepage = "http://fullstackreact.com"
13+
s.license = package['license']
14+
s.author = "Ari Lerner"
15+
s.source = { :git => "https://github.com/fullstackreact/react-native-firestack.git", :tag => "v#{s.version}" }
16+
s.social_media_url = 'http://twitter.com/fullstackio'
17+
s.platform = :ios, "8.0"
18+
s.header_dir = 'ios/Firestack'
19+
s.preserve_paths = 'README.md', 'package.json', '*.js'
20+
s.source_files = 'ios/Firestack/*.{h,m}'
21+
s.dependency 'React'
22+
s.dependency 'Firebase/Auth'
23+
s.dependency 'Firebase/Core'
24+
s.dependency 'Firebase/Database'
25+
s.dependency 'Firebase/Messaging'
26+
s.dependency 'Firebase/RemoteConfig'
27+
s.dependency 'Firebase/Storage'
28+
end

android/src/main/java/io/fullstack/firestack/auth/FirestackAuth.java

+68-9
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import com.google.firebase.auth.UserProfileChangeRequest;
2626
import com.google.firebase.auth.FacebookAuthProvider;
2727
import com.google.firebase.auth.FirebaseAuth;
28+
import com.google.firebase.auth.FirebaseAuthException;
2829
import com.google.firebase.auth.FirebaseUser;
2930
import com.google.firebase.auth.GetTokenResult;
3031
import com.google.firebase.auth.GoogleAuthProvider;
32+
import com.google.firebase.auth.EmailAuthProvider;
33+
3134

3235
import io.fullstack.firestack.Utils;
3336

@@ -50,7 +53,7 @@ public FirestackAuth(ReactApplicationContext reactContext) {
5053
mReactContext = reactContext;
5154
mAuth = FirebaseAuth.getInstance();
5255

53-
Log.d(TAG, "New FirestackAuth instance");
56+
Log.d(TAG, "New FirestackAuth instance");
5457
}
5558

5659
@Override
@@ -165,6 +168,43 @@ public void signInWithProvider(final String provider, final String authToken, fi
165168
Utils.todoNote(TAG, "signInWithProvider", callback);
166169
}
167170

171+
@ReactMethod
172+
public void linkPassword(final String email, final String password, final Callback callback) {
173+
FirebaseUser user = mAuth.getCurrentUser();
174+
175+
if (user != null) {
176+
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
177+
user
178+
.linkWithCredential(credential)
179+
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
180+
@Override
181+
public void onComplete(@NonNull Task<AuthResult> task) {
182+
try {
183+
if (task.isSuccessful()) {
184+
Log.d(TAG, "user linked with password credential");
185+
userCallback(mAuth.getCurrentUser(), callback);
186+
} else {
187+
userErrorCallback(task, callback);
188+
}
189+
} catch (Exception ex) {
190+
userExceptionCallback(ex, callback);
191+
}
192+
}
193+
});
194+
} else {
195+
callbackNoUser(callback, true);
196+
}
197+
}
198+
199+
@ReactMethod
200+
public void link(final String provider, final String authToken, final String authSecret, final Callback callback) {
201+
if (provider.equals("password")) {
202+
linkPassword(authToken, authSecret, callback);
203+
} else
204+
// TODO other providers
205+
Utils.todoNote(TAG, "linkWithProvider", callback);
206+
}
207+
168208
@ReactMethod
169209
public void signInAnonymously(final Callback callback) {
170210
Log.d(TAG, "signInAnonymously:called:");
@@ -435,9 +475,32 @@ public void signOut(final Callback callback) {
435475
callback.invoke(null, resp);
436476
}
437477

478+
@ReactMethod
479+
public void reloadUser(final Callback callback) {
480+
FirebaseUser user = mAuth.getCurrentUser();
481+
482+
if (user == null) {
483+
callbackNoUser(callback, false);
484+
} else {
485+
user.reload()
486+
.addOnCompleteListener(new OnCompleteListener<Void>() {
487+
@Override
488+
public void onComplete(@NonNull Task<Void> task) {
489+
if (task.isSuccessful()) {
490+
Log.d(TAG, "user reloaded");
491+
userCallback(mAuth.getCurrentUser(), callback);
492+
} else {
493+
userErrorCallback(task, callback);
494+
}
495+
}
496+
});
497+
}
498+
}
499+
438500
@ReactMethod
439501
public void getCurrentUser(final Callback callback) {
440502
FirebaseUser user = mAuth.getCurrentUser();
503+
441504
if (user == null) {
442505
callbackNoUser(callback, false);
443506
} else {
@@ -513,19 +576,15 @@ public void onComplete(@NonNull Task<GetTokenResult> task) {
513576

514577
private void userErrorCallback(Task task, final Callback onFail) {
515578
WritableMap error = Arguments.createMap();
516-
error.putInt("errorCode", task.getException().hashCode());
517-
error.putString("errorMessage", task.getException().getMessage());
518-
error.putString("allErrorMessage", task.getException().toString());
519-
579+
error.putString("code", ((FirebaseAuthException) task.getException()).getErrorCode());
580+
error.putString("message", task.getException().getMessage());
520581
onFail.invoke(error);
521582
}
522583

523584
private void userExceptionCallback(Exception ex, final Callback onFail) {
524585
WritableMap error = Arguments.createMap();
525-
error.putInt("errorCode", ex.hashCode());
526-
error.putString("errorMessage", ex.getMessage());
527-
error.putString("allErrorMessage", ex.toString());
528-
586+
error.putInt("code", ex.hashCode());
587+
error.putString("message", ex.getMessage());
529588
onFail.invoke(error);
530589
}
531590

android/src/main/java/io/fullstack/firestack/database/FirestackDatabaseReference.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
6868

6969
@Override
7070
public void onCancelled(DatabaseError error) {
71-
handleDatabaseError(eventName, error);
71+
handleDatabaseError(error);
7272
}
7373
};
7474
mQuery.addChildEventListener(mEventListener);
@@ -90,7 +90,7 @@ public void onDataChange(DataSnapshot dataSnapshot) {
9090

9191
@Override
9292
public void onCancelled(DatabaseError error) {
93-
handleDatabaseError("value", error);
93+
handleDatabaseError(error);
9494
}
9595
};
9696
mQuery.addValueEventListener(mValueListener);
@@ -162,22 +162,22 @@ private void handleDatabaseEvent(final String name, final DataSnapshot dataSnaps
162162
WritableMap data = Utils.dataSnapshotToMap(name, mPath, mModifiersString, dataSnapshot);
163163
WritableMap evt = Arguments.createMap();
164164
evt.putString("eventName", name);
165-
evt.putString("path", mPath);
166-
evt.putString("modifiersString", mModifiersString);
167165
evt.putMap("body", data);
168166

169167
Utils.sendEvent(mReactContext, "database_event", evt);
170168
}
171169

172-
private void handleDatabaseError(final String name, final DatabaseError error) {
170+
private void handleDatabaseError(final DatabaseError error) {
173171
WritableMap err = Arguments.createMap();
172+
err.putString("eventName", "database_error");
173+
err.putString("path", mPath);
174+
err.putString("modifiersString", mModifiersString);
174175
err.putInt("errorCode", error.getCode());
175176
err.putString("errorDetails", error.getDetails());
176-
err.putString("description", error.getMessage());
177+
err.putString("msg", error.getMessage());
177178

178179
WritableMap evt = Arguments.createMap();
179-
evt.putString("eventName", name);
180-
evt.putString("path", mPath);
180+
evt.putString("eventName", "database_error");
181181
evt.putMap("body", err);
182182

183183
Utils.sendEvent(mReactContext, "database_error", evt);

android/src/main/java/io/fullstack/firestack/messaging/FirestackMessaging.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,42 @@ public void unsubscribeFromTopic(String topic, final Callback callback) {
165165
}
166166
}
167167

168+
// String senderId, String messageId, String messageType,
168169
@ReactMethod
169-
public void send(String senderId, String messageId, String messageType, ReadableMap params, final Callback callback) {
170+
public void send(ReadableMap params, final Callback callback) {
171+
ReadableMap data = params.getMap("data");
170172
FirebaseMessaging fm = FirebaseMessaging.getInstance();
171-
RemoteMessage.Builder remoteMessage = new RemoteMessage.Builder(senderId);
172-
remoteMessage.setMessageId(messageId);
173-
remoteMessage.setMessageType(messageType);
174-
ReadableMapKeySetIterator iterator = params.keySetIterator();
173+
RemoteMessage.Builder remoteMessage = new RemoteMessage.Builder(params.getString("sender"));
174+
175+
remoteMessage.setMessageId(params.getString("id"));
176+
remoteMessage.setMessageType(params.getString("type"));
177+
178+
if (params.hasKey("ttl")) {
179+
remoteMessage.setTtl(params.getInt("ttl"));
180+
}
181+
182+
if (params.hasKey("collapseKey")) {
183+
remoteMessage.setCollapseKey(params.getString("collapseKey"));
184+
}
185+
186+
ReadableMapKeySetIterator iterator = data.keySetIterator();
175187

176188
while (iterator.hasNextKey()) {
177189
String key = iterator.nextKey();
178-
ReadableType type = params.getType(key);
190+
ReadableType type = data.getType(key);
179191
if (type == ReadableType.String) {
180-
remoteMessage.addData(key, params.getString(key));
181-
Log.d(TAG, "Firebase send: " + key);
182-
Log.d(TAG, "Firebase send: " + params.getString(key));
192+
remoteMessage.addData(key, data.getString(key));
183193
}
184194
}
185195

186196
try {
187197
fm.send(remoteMessage.build());
188198
WritableMap res = Arguments.createMap();
189199
res.putString("status", "success");
200+
Log.d(TAG, "send: Message sent");
190201
callback.invoke(null, res);
191202
} catch (Exception e) {
192-
Log.e(TAG, "Error sending message", e);
203+
Log.e(TAG, "send: error sending message", e);
193204
WritableMap error = Arguments.createMap();
194205
error.putString("code", e.toString());
195206
error.putString("message", e.toString());

docs/api/authentication.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Sign in the user with a 3rd party credential provider. `credential` requires the
100100

101101
```javascript
102102
const credential = {
103-
provider: 'facebook.com',
103+
provider: 'facebook',
104104
token: '12345',
105105
secret: '6789',
106106
};
@@ -227,7 +227,7 @@ Refreshes the current user.
227227

228228
```javascript
229229
firestack.auth().currentUser
230-
.getToken()
230+
.reload()
231231
.then((user) => {})
232232
.catch();
233233
```

docs/api/database.md

+28
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ firestack.database()
2525
});
2626
```
2727

28+
Test value exists at location:
29+
```javascript
30+
firestack.database()
31+
.ref('posts/1234')
32+
.on('value', (snapshot) => {
33+
const exists = snapshot.exists();
34+
});
35+
```
36+
37+
Basic write with priority example:
38+
```javascript
39+
firestack.database()
40+
.ref('posts/1235')
41+
.setWithPriority({
42+
title: 'Another Awesome Post',
43+
content: 'Some awesome content',
44+
}, 10);
45+
```
46+
Useful for `orderByPriority` queries.
47+
48+
49+
Transaction Support:
50+
```javascript
51+
firestack.database()
52+
.ref('posts/1234/title')
53+
.transaction((title) => 'My Awesome Post');
54+
```
55+
2856
## Unmounted components
2957

3058
Listening to database updates on unmounted components will trigger a warning:

docs/api/storage

-1
This file was deleted.

0 commit comments

Comments
 (0)