Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 806edee

Browse files
firebase user provider data? #196
1 parent 59191d9 commit 806edee

File tree

5 files changed

+56
-36
lines changed

5 files changed

+56
-36
lines changed

firebase.android.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,7 @@ firebase.getCurrentUser = function (arg) {
466466
var firebaseAuth = com.google.firebase.auth.FirebaseAuth.getInstance();
467467
var user = firebaseAuth.getCurrentUser();
468468
if (user !== null) {
469-
resolve({
470-
uid: user.getUid(),
471-
name: user.getDisplayName(),
472-
email: user.getEmail(),
473-
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
474-
});
469+
resolve(toLoginResult(user));
475470
} else {
476471
reject();
477472
}
@@ -574,11 +569,24 @@ function toLoginResult(user) {
574569
return false;
575570
}
576571

572+
// for convenience return the result in multiple formats
573+
var providers = [];
574+
var providerData = user.getProviderData();
575+
for (var i = 0; i < providerData.size(); i++) {
576+
var pid = providerData.get(i).getProviderId();
577+
providers.push({
578+
id: pid
579+
});
580+
}
581+
577582
return {
578583
uid: user.getUid(),
579584
name: user.getDisplayName(),
580585
email: user.getEmail(),
581-
// expiresAtUnixEpochSeconds: authData.getExpires(),
586+
emailVerified: user.isEmailVerified(),
587+
// provider: user.getProviderId(), // always 'firebase'
588+
providers: providers,
589+
anonymous: user.isAnonymous(),
582590
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
583591
};
584592
}

firebase.ios.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,7 @@ firebase.getCurrentUser = function (arg) {
613613

614614
var user = fAuth.currentUser;
615615
if (user) {
616-
resolve({
617-
uid: user.uid,
618-
// anonymous: user.anonymous,
619-
// provider: user.providerID,
620-
profileImageURL: user.photoURL ? user.photoURL.absoluteString : null,
621-
email: user.email,
622-
emailVerified: user.emailVerified,
623-
name: user.displayName,
624-
refreshToken: user.refreshToken
625-
});
616+
resolve(toLoginResult(user));
626617
} else {
627618
reject();
628619
}
@@ -681,16 +672,30 @@ firebase.logout = function (arg) {
681672
};
682673

683674
function toLoginResult(user) {
684-
return user && {
685-
uid: user.uid,
686-
// anonymous: user.anonymous,
687-
// provider: user.providerID,
688-
profileImageURL: user.photoURL ? user.photoURL.absoluteString : null,
689-
email: user.email,
690-
emailVerified: user.emailVerified,
691-
name: user.displayName,
692-
refreshToken: user.refreshToken
693-
};
675+
if (!user) {
676+
return false;
677+
}
678+
679+
var providers = [];
680+
for (i = 0, l = user.providerData.count; i < l; i++) {
681+
var firUserInfo = user.providerData.objectAtIndex(i);
682+
var pid = firUserInfo.valueForKey("providerID");
683+
providers.push({
684+
id: pid
685+
});
686+
}
687+
688+
return {
689+
uid: user.uid,
690+
anonymous: user.anonymous,
691+
// provider: user.providerID, // always 'Firebase'
692+
providers: providers,
693+
profileImageURL: user.photoURL ? user.photoURL.absoluteString : null,
694+
email: user.email,
695+
emailVerified: user.emailVerified,
696+
name: user.displayName,
697+
refreshToken: user.refreshToken
698+
};
694699
}
695700

696701
firebase.getAuthToken = function (arg) {

index.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export interface GetAuthTokenOptions {
162162
forceRefresh?: boolean;
163163
}
164164

165+
export interface Provider {
166+
id: string;
167+
}
168+
165169
/**
166170
* The options object passed into the login function.
167171
*/
@@ -193,11 +197,13 @@ export interface LoginOptions {
193197
export interface User {
194198
uid: string;
195199
email?: string;
200+
emailVerified: boolean;
196201
name?: string;
197-
provider?: LoginType;
198-
expiresAtUnixEpochSeconds?: number;
202+
anonymous: boolean;
203+
providers: Array<Provider>;
199204
profileImageURL?: string;
200-
token?: string;
205+
/** iOS only */
206+
refreshToken?: string;
201207
}
202208

203209
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "3.8.2",
3+
"version": "3.8.3",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase.js",
66
"typings": "index.d.ts",

scripts/installer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var directories = {
1414
console.log('NativeScript Firebase Plugin Installation');
1515

1616
var appRoot = "../../";
17-
var pluginConfigPath = path.join(appRoot, "firebase.nativescript.json");
17+
var pluginConfigFile = "firebase.nativescript.json";
18+
var pluginConfigPath = path.join(appRoot, pluginConfigFile);
1819

1920
var config = {};
2021
function mergeConfig(result) {
@@ -29,20 +30,20 @@ function readConfig() {
2930
try {
3031
config = JSON.parse(fs.readFileSync(pluginConfigPath));
3132
} catch(e) {
32-
console.log("Failed reading config at " + pluginConfigPath);
33+
console.log("Failed reading " + pluginConfigFile);
3334
console.log(e);
3435
config = {};
3536
}
3637
}
3738

3839
if (process.argv.indexOf("config") == -1 && fs.existsSync(pluginConfigPath)) {
3940
readConfig();
40-
console.log("Config exists at: " + pluginConfigPath);
41+
console.log("Config file exists (" + pluginConfigFile + ")");
4142
askiOSPromptResult(config);
4243
askAndroidPromptResult(config);
4344
promptQuestionsResult(config);
4445
} else {
45-
console.log("No existing config found at: " + pluginConfigPath + ", so let's configure the Firebase plugin!");
46+
console.log("No existing " + pluginConfigFile + " config file found, so let's configure the Firebase plugin!");
4647
prompt.start();
4748
askiOSPrompt();
4849
}
@@ -146,7 +147,7 @@ function promptQuestionsResult(result) {
146147
function askSaveConfigPrompt() {
147148
prompt.get({
148149
name: 'save_config',
149-
description: 'Do you want to save the selected configuration. Reinstalling the dependency will reuse the setup from: ' + pluginConfigPath + '. CI will be easier. (y/n)',
150+
description: 'Do you want to save the selected configuration. Reinstalling the dependency will reuse the setup from: ' + pluginConfigFile + '. CI will be easier. (y/n)',
150151
default: 'y'
151152
}, function (err, result) {
152153
if (err) {

0 commit comments

Comments
 (0)