cordova-plugin-firebase-authentication 4.0.2 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,109 +1,369 @@
1
- var exec = require("cordova/exec");
2
1
  var PLUGIN_NAME = "FirebaseAuthentication";
2
+ // @ts-ignore
3
+ var exec = require("cordova/exec");
4
+
5
+ exports.onAuthStateChanged =
6
+ /**
7
+ * Registers a block as an auth state did change listener. To be invoked when:
8
+ * - The block is registered as a listener,
9
+ * - A user with a different UID from the current user has signed in, or
10
+ * - The current user has signed out.
11
+ * @param {(userDetails: UserDetails | null) => void} callback Callback function
12
+ * @param {(error: string) => void} [errorCallback] Error callback function
13
+ */
14
+ function(callback, errorCallback) {
15
+ exec(callback, errorCallback, PLUGIN_NAME, "setAuthStateChanged", [false]);
16
+
17
+ return function() {
18
+ exec(null, errorCallback, PLUGIN_NAME, "setAuthStateChanged", [true]);
19
+ };
20
+ };
21
+
22
+ exports.getCurrentUser =
23
+ /**
24
+ * Returns the current user in the Firebase instance.
25
+ * @returns {Promise<UserDetails>} Fulfills promise with user details
26
+ */
27
+ function() {
28
+ return new Promise(function (resolve, reject) {
29
+ exec(resolve, reject, PLUGIN_NAME, "getCurrentUser", []);
30
+ });
31
+ };
32
+
33
+ exports.getIdToken =
34
+ /**
35
+ * Returns a JWT token used to identify the user to a Firebase service.
36
+ * @param {boolean} forceRefresh When <code>true</code> cached value is ignored
37
+ * @returns {Promise<string>} Fulfills promis with id token string value
38
+ *
39
+ * @example
40
+ * cordova.plugins.firebase.auth.getIdToken().then(function(idToken) {
41
+ * // send token to server
42
+ * });
43
+ */
44
+ function(forceRefresh) {
45
+ return new Promise(function(resolve, reject) {
46
+ if (forceRefresh == null) forceRefresh = false;
47
+
48
+ exec(resolve, reject, PLUGIN_NAME, "getIdToken", [forceRefresh]);
49
+ });
50
+ };
51
+
52
+ exports.createUserWithEmailAndPassword =
53
+ /**
54
+ * Creates a new user account with the given email address and password.
55
+ * @param {string} email User account email
56
+ * @param {string} password User accound password
57
+ * @returns {Promise<void>} Callback when operation is completed
58
+ *
59
+ * @example
60
+ * cordova.plugins.firebase.auth.createUserWithEmailAndPassword("my@mail.com", "pa55w0rd");
61
+ */
62
+ function(email, password) {
63
+ return new Promise(function(resolve, reject) {
64
+ exec(resolve, reject, PLUGIN_NAME, "createUserWithEmailAndPassword", [email, password]);
65
+ });
66
+ };
67
+
68
+ exports.sendEmailVerification =
69
+ /**
70
+ * Initiates email verification for the current user.
71
+ * @returns {Promise<void>} Callback when operation is completed
72
+ *
73
+ * @example
74
+ * cordova.plugins.firebase.auth.sendEmailVerification();
75
+ */
76
+ function() {
77
+ return new Promise(function(resolve, reject) {
78
+ exec(resolve, reject, PLUGIN_NAME, "sendEmailVerification", []);
79
+ });
80
+ };
81
+
82
+ exports.sendPasswordResetEmail =
83
+ /**
84
+ * Triggers the Firebase Authentication backend to send a password-reset email
85
+ * to the given email address, which must correspond to an existing user of your app.
86
+ * @param {string} email User account email
87
+ * @returns {Promise<void>} Callback when operation is completed
88
+ *
89
+ * @example
90
+ * cordova.plugins.firebase.auth.sendPasswordResetEmail("my@mail.com");
91
+ */
92
+ function(email) {
93
+ return new Promise(function(resolve, reject) {
94
+ exec(resolve, reject, PLUGIN_NAME, "sendPasswordResetEmail", [email]);
95
+ });
96
+ };
97
+
98
+ exports.signInWithEmailAndPassword =
99
+ /**
100
+ * Triggers the Firebase Authentication backend to send a password-reset email
101
+ * to the given email address, which must correspond to an existing user of your app.
102
+ * @param {string} email User account email
103
+ * @param {string} password User accound password
104
+ * @returns {Promise<void>} Callback when operation is completed
105
+ *
106
+ * @example
107
+ * cordova.plugins.firebase.auth.signInWithEmailAndPassword("my@mail.com", "pa55w0rd");
108
+ */
109
+ function(email, password) {
110
+ return new Promise(function(resolve, reject) {
111
+ exec(resolve, reject, PLUGIN_NAME, "signInWithEmailAndPassword", [email, password]);
112
+ });
113
+ };
114
+
115
+ exports.signInAnonymously =
116
+ /**
117
+ * Create and use temporary anonymous account to authenticate with Firebase.
118
+ * @returns {Promise<void>} Callback when operation is completed
119
+ *
120
+ * @example
121
+ * cordova.plugins.firebase.auth.signInAnonymously();
122
+ */
123
+ function() {
124
+ return new Promise(function(resolve, reject) {
125
+ exec(resolve, reject, PLUGIN_NAME, "signInAnonymously", []);
126
+ });
127
+ };
128
+
129
+ exports.signInWithGoogle =
130
+ /**
131
+ * Uses Google's <code>idToken</code> and <code>accessToken</code> to sign-in into firebase account.
132
+ * @param {string} idToken Google ID token
133
+ * @param {string} accessToken Google Access token
134
+ * @returns {Promise<void>} Callback when operation is completed
135
+ *
136
+ * @example
137
+ * // Below we use cordova-plugin-googleplus to trigger Google Login UI
138
+ * window.plugins.googleplus.login({
139
+ * scopes: '... ',
140
+ * webClientId: '1234...',
141
+ * offline: true
142
+ * }, function(res) {
143
+ * cordova.plugins.firebase.auth.signInWithGoogle(res.idToken, res.accessToken).then(function() {
144
+ * console.log("Firebase logged in with Google");
145
+ * }, function(err) {
146
+ * console.error("Firebase login failed", err);
147
+ * });
148
+ * }, function(err) {
149
+ * console.error("Google login failed", err);
150
+ * });
151
+ */
152
+ function(idToken, accessToken) {
153
+ return new Promise(function(resolve, reject) {
154
+ exec(resolve, reject, PLUGIN_NAME, "signInWithGoogle", [idToken, accessToken]);
155
+ });
156
+ };
3
157
 
4
- module.exports = {
5
- onAuthStateChanged: function(callback) {
6
- exec(callback, null, PLUGIN_NAME, "setAuthStateChanged", [false]);
7
-
8
- return function() {
9
- exec(null, null, PLUGIN_NAME, "setAuthStateChanged", [true]);
10
- };
11
- },
12
- getCurrentUser: function () {
13
- return new Promise(function (resolve, reject) {
14
- exec(resolve, reject, PLUGIN_NAME, "getCurrentUser", []);
15
- });
16
- },
17
- getIdToken: function(forceRefresh) {
18
- return new Promise(function(resolve, reject) {
19
- if (forceRefresh == null) forceRefresh = false;
20
-
21
- exec(resolve, reject, PLUGIN_NAME, "getIdToken", [forceRefresh]);
22
- });
23
- },
24
- createUserWithEmailAndPassword: function(email, password) {
25
- return new Promise(function(resolve, reject) {
26
- exec(resolve, reject, PLUGIN_NAME, "createUserWithEmailAndPassword", [email, password]);
27
- });
28
- },
29
- sendEmailVerification: function() {
30
- return new Promise(function(resolve, reject) {
31
- exec(resolve, reject, PLUGIN_NAME, "sendEmailVerification", []);
32
- });
33
- },
34
- sendPasswordResetEmail: function(email) {
35
- return new Promise(function(resolve, reject) {
36
- exec(resolve, reject, PLUGIN_NAME, "sendPasswordResetEmail", [email]);
37
- });
38
- },
39
- signInWithEmailAndPassword: function(email, password) {
40
- return new Promise(function(resolve, reject) {
41
- exec(resolve, reject, PLUGIN_NAME, "signInWithEmailAndPassword", [email, password]);
42
- });
43
- },
44
- signInAnonymously: function(email, password) {
45
- return new Promise(function(resolve, reject) {
46
- exec(resolve, reject, PLUGIN_NAME, "signInAnonymously", []);
47
- });
48
- },
49
- signInWithGoogle: function(idToken, accessToken) {
50
- return new Promise(function(resolve, reject) {
51
- exec(resolve, reject, PLUGIN_NAME, "signInWithGoogle", [idToken, accessToken]);
52
- });
53
- },
54
- signInWithFacebook: function(accessToken) {
55
- return new Promise(function(resolve, reject) {
56
- exec(resolve, reject, PLUGIN_NAME, "signInWithFacebook", [accessToken]);
57
- });
58
- },
59
- signInWithTwitter: function(token, secret) {
60
- return new Promise(function(resolve, reject) {
61
- exec(resolve, reject, PLUGIN_NAME, "signInWithTwitter", [token, secret]);
62
- });
63
- },
64
- signInWithApple: function(idToken, rawNonce) {
65
- return new Promise(function(resolve, reject) {
66
- exec(resolve, reject, PLUGIN_NAME, "signInWithApple", [idToken, rawNonce || null]);
67
- });
68
- },
69
- verifyPhoneNumber: function(phoneNumber, timeoutMillis) {
70
- return new Promise(function(resolve, reject) {
71
- exec(resolve, reject, PLUGIN_NAME, "verifyPhoneNumber", [phoneNumber, timeoutMillis]);
72
- });
73
- },
74
- signInWithVerificationId: function(verificationId, code) {
75
- return new Promise(function(resolve, reject) {
76
- exec(resolve, reject, PLUGIN_NAME, "signInWithVerificationId", [verificationId, code]);
77
- });
78
- },
79
- signInWithCustomToken: function (idToken) {
80
- return new Promise(function (resolve, reject) {
81
- exec(resolve, reject, PLUGIN_NAME, "signInWithCustomToken", [idToken]);
82
- })
83
- },
84
- signOut: function() {
85
- return new Promise(function(resolve, reject) {
86
- exec(resolve, reject, PLUGIN_NAME, "signOut", []);
87
- });
88
- },
89
- setLanguageCode: function(languageCode) {
90
- return new Promise(function(resolve, reject) {
91
- exec(resolve, reject, PLUGIN_NAME, "setLanguageCode", [languageCode]);
92
- });
93
- },
94
- useAppLanguage: function() {
95
- return new Promise(function(resolve, reject) {
96
- exec(resolve, reject, PLUGIN_NAME, "setLanguageCode", [null]);
97
- });
98
- },
99
- updateProfile: function(profile) {
100
- return new Promise(function(resolve, reject) {
101
- exec(resolve, reject, PLUGIN_NAME, "updateProfile", [profile || {}]);
102
- });
103
- },
104
- useEmulator: function(host, port) {
105
- return new Promise(function(resolve, reject) {
106
- exec(resolve, reject, PLUGIN_NAME, "useEmulator", [host, port]);
107
- });
108
- }
158
+ exports.signInWithFacebook =
159
+ /**
160
+ * Uses Facebook's <code>accessToken</code> to sign-in into firebase account. In order to
161
+ * retrieve those tokens follow instructions for iOS and Android from Firebase docs.
162
+ * @param {string} accessToken Facebook's access token string
163
+ * @returns {Promise<void>} Callback when operation is completed
164
+ *
165
+ * @see https://firebase.google.com/docs/auth/android/facebook-login
166
+ * @see https://firebase.google.com/docs/auth/ios/facebook-login
167
+ */
168
+ function(accessToken) {
169
+ return new Promise(function(resolve, reject) {
170
+ exec(resolve, reject, PLUGIN_NAME, "signInWithFacebook", [accessToken]);
171
+ });
109
172
  };
173
+
174
+ exports.signInWithTwitter =
175
+ /**
176
+ * Uses Twitter's <code>token</code> and <code>secret</code> to sign-in into firebase account.
177
+ * In order to retrieve those tokens follow instructions for iOS and Android from Firebase docs.
178
+ * @param {string} token Twitter's token string
179
+ * @param {string} secret Twitter's secret string
180
+ * @returns {Promise<void>} Callback when operation is completed
181
+ *
182
+ * @see https://firebase.google.com/docs/auth/android/twitter-login
183
+ * @see https://firebase.google.com/docs/auth/ios/twitter-login
184
+ */
185
+ function(token, secret) {
186
+ return new Promise(function(resolve, reject) {
187
+ exec(resolve, reject, PLUGIN_NAME, "signInWithTwitter", [token, secret]);
188
+ });
189
+ };
190
+
191
+ exports.signInWithApple =
192
+ /**
193
+ * Uses Apples's <code>idToken</code> and <code>rawNonce</code> to sign-in into firebase account. For getting _idToken_ (_rawNonce_ is optional) you can use `cordova-plugin-sign-in-with-apple` (or any other cordova plugin for Apple Sign-In).
194
+ * @param {string} idToken Apple's ID token string
195
+ * @param {string} rawNonce Apple's raw token string
196
+ * @returns {Promise<void>} Callback when operation is completed
197
+ *
198
+ * @example
199
+ * // below we use cordova-plugin-sign-in-with-apple to trigger Apple Login UI
200
+ * cordova.plugins.SignInWithApple.signin({
201
+ * requestedScopes: [0, 1]
202
+ * }, function(res) {
203
+ * cordova.plugins.firebase.auth.signInWithApple(res.identityToken).then(function() {
204
+ * console.log("Firebase logged in with Apple");
205
+ * }, function(err) {
206
+ * console.error("Firebase login failed", err);
207
+ * });
208
+ * }, function(err) {
209
+ * console.error("Apple signin failed", err);
210
+ * });
211
+ */
212
+ function(idToken, rawNonce) {
213
+ return new Promise(function(resolve, reject) {
214
+ exec(resolve, reject, PLUGIN_NAME, "signInWithApple", [idToken, rawNonce || null]);
215
+ });
216
+ };
217
+
218
+ exports.signInWithCustomToken =
219
+ /**
220
+ * You can integrate Firebase Authentication with a custom authentication system
221
+ * by modifying your authentication server to produce custom signed tokens when
222
+ * a user successfully signs in. Your app receives this token and uses it to
223
+ * authenticate with Firebase.
224
+ * @param {string} authToken Custom auth token
225
+ * @returns {Promise<void>} Callback when operation is completed
226
+ *
227
+ * @see https://firebase.google.com/docs/auth/android/custom-auth
228
+ * @see https://firebase.google.com/docs/auth/ios/custom-auth
229
+ */
230
+ function(authToken) {
231
+ return new Promise(function (resolve, reject) {
232
+ exec(resolve, reject, PLUGIN_NAME, "signInWithCustomToken", [authToken]);
233
+ })
234
+ };
235
+
236
+ exports.signOut =
237
+ /**
238
+ * Signs out the current user and clears it from the disk cache.
239
+ * @returns {Promise<void>} Callback when operation is completed
240
+ *
241
+ * @example
242
+ * cordova.plugins.firebase.auth.signOut();
243
+ */
244
+ function() {
245
+ return new Promise(function(resolve, reject) {
246
+ exec(resolve, reject, PLUGIN_NAME, "signOut", []);
247
+ });
248
+ };
249
+
250
+ exports.verifyPhoneNumber =
251
+ /**
252
+ * Starts the phone number verification process for the given phone number.
253
+ *
254
+ * Android supports auto-verify and instant device verification.
255
+ * <b>You must register `onAuthStateChanged` to get callback on instant verification.</b>
256
+ *
257
+ * Maximum allowed value for timeout is 2 minutes. Use 0 to disable SMS-auto-retrieval.
258
+ * If you specify a positive value less than 30 seconds, library will default to 30 seconds.
259
+ * @param {string} phoneNumber Phone number in international format
260
+ * @param {number} [timeoutMillis] Maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library.
261
+ * @returns {Promise<string>} Fulfills promise with <code>verificationId</code> to use later for signing in
262
+ */
263
+ function(phoneNumber, timeoutMillis) {
264
+ return new Promise(function(resolve, reject) {
265
+ exec(resolve, reject, PLUGIN_NAME, "verifyPhoneNumber", [phoneNumber, timeoutMillis]);
266
+ });
267
+ };
268
+
269
+ exports.signInWithVerificationId =
270
+ /**
271
+ * Completes phone number verification process and use it to sign in.
272
+ * @param {string} verificationId [description]
273
+ * @param {string} code 6-digit SMS code
274
+ * @returns {Promise<void>} Callback when operation is completed
275
+ *
276
+ * @example
277
+ * cordova.plugins.firebase.auth.verifyPhoneNumber("+123456789").then(function(verificationId) {
278
+ * var code = prompt("Enter verification code");
279
+ * if (code) {
280
+ * return cordova.plugins.firebase.auth.signInWithVerificationId(verificationId, code);
281
+ * }
282
+ * }).catch(function(err) {
283
+ * console.error("Phone number verification failed", err);
284
+ * });
285
+ */
286
+ function(verificationId, code) {
287
+ return new Promise(function(resolve, reject) {
288
+ exec(resolve, reject, PLUGIN_NAME, "signInWithVerificationId", [verificationId, code]);
289
+ });
290
+ };
291
+
292
+ exports.useEmulator =
293
+ /**
294
+ * Sets languageCode to the app’s current language.
295
+ * @param {string} host Emulator host name
296
+ * @param {number} port Emulator port
297
+ * @returns {Promise<void>} Callback when operation is completed
298
+ *
299
+ * @example
300
+ * cordova.plugins.firebase.auth.useEmulator('localhost', 8000);
301
+ */
302
+ function(host, port) {
303
+ return new Promise(function(resolve, reject) {
304
+ exec(resolve, reject, PLUGIN_NAME, "useEmulator", [host, port]);
305
+ });
306
+ };
307
+
308
+
309
+ exports.updateProfile =
310
+ /**
311
+ * Updates the current user's profile data.
312
+ * Passing a `null` value will delete the current attribute's value, but not
313
+ * passing a property won't change the current attribute's value.
314
+ * @param {{displayName: string; photoURL: string}} profileDetails User attributes.
315
+ * @returns {Promise<void>} Callback when operation is completed
316
+ *
317
+ * @example
318
+ * cordova.plugins.firebase.auth.updateProfile({
319
+ * displayName: "Jane Q. User",
320
+ * photoURL: "https://example.com/jane-q-user/profile.jpg",
321
+ * });
322
+ */
323
+ function(profileDetails) {
324
+ return new Promise(function(resolve, reject) {
325
+ exec(resolve, reject, PLUGIN_NAME, "updateProfile", [profileDetails || {}]);
326
+ });
327
+ };
328
+
329
+ exports.useAppLanguage =
330
+ /**
331
+ * Sets languageCode to the app’s current language.
332
+ * @returns {Promise<void>} Callback when operation is completed
333
+ *
334
+ * @example
335
+ * cordova.plugins.firebase.auth.useAppLanguage();
336
+ */
337
+ function() {
338
+ return new Promise(function(resolve, reject) {
339
+ exec(resolve, reject, PLUGIN_NAME, "setLanguageCode", [null]);
340
+ });
341
+ };
342
+
343
+ exports.useEmulator =
344
+ /**
345
+ * Sets Firebase to use auth emulator with specific settings.
346
+ * @param {string} host Emulator host name
347
+ * @param {number} port Emulator port
348
+ * @returns {Promise<void>} Callback when operation is completed
349
+ *
350
+ * @example
351
+ * cordova.plugins.firebase.auth.useEmulator('localhost', 8000);
352
+ */
353
+ function(host, port) {
354
+ return new Promise(function(resolve, reject) {
355
+ exec(resolve, reject, PLUGIN_NAME, "useEmulator", [host, port]);
356
+ });
357
+ };
358
+
359
+ /**
360
+ * Represents a user's profile information in your Firebase project's user database.
361
+ * @typedef UserDetails
362
+ * @property {string} uid String used to uniquely identify your user in your Firebase project's user database
363
+ * @property {string} displayName Main display name of this user from the Firebase project's user database
364
+ * @property {string} email Main email address of the user, as stored in the Firebase project's user database.
365
+ * @property {boolean} emailVerified <code>true</code> if the user's email is verified.
366
+ * @property {string | null} phoneNumber Phone number of the user, as stored in the Firebase project's user database, or null if none exists.
367
+ * @property {string} photoURL URL of this user's main profile picture, as stored in the Firebase project's user database.
368
+ * @property {string} providerId
369
+ */