Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 0c183d4

Browse files
author
jacobawenger
committed
Added JSDoc annotations for all auth methods
1 parent 709fd75 commit 0c183d4

File tree

1 file changed

+147
-24
lines changed

1 file changed

+147
-24
lines changed

src/FirebaseAuth.js

Lines changed: 147 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@
6262
/********************/
6363
/* Authentication */
6464
/********************/
65-
// Common login completion handler for all authentication methods.
65+
/**
66+
* Common login completion handler for all authentication methods.
67+
*
68+
* @param {Promise} deferred A deferred promise which is either resolved or rejected.
69+
* @param {Error|null} error A Firebase error if authentication fails.
70+
* @param {Object|null} authData The authentication state upon successful authentication.
71+
*/
6672
_onLoginHandler: function(deferred, error, authData) {
6773
if (error !== null) {
6874
deferred.reject(error);
@@ -71,7 +77,16 @@
7177
}
7278
},
7379

74-
// Authenticates the Firebase reference with a custom authentication token.
80+
/**
81+
* Authenticates the Firebase reference with a custom authentication token.
82+
*
83+
* @param {string} authToken An authentication token or a Firebase Secret. A Firebase Secret
84+
* should only be used for authenticating a server process and provides full read / write
85+
* access to the entire Firebase.
86+
* @param {Object} [options] An object containing optional client arguments, such as configuring
87+
* session persistence.
88+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
89+
*/
7590
authWithCustomToken: function(authToken, options) {
7691
var deferred = this._q.defer();
7792

@@ -80,7 +95,13 @@
8095
return deferred.promise;
8196
},
8297

83-
// Authenticates the Firebase reference anonymously.
98+
/**
99+
* Authenticates the Firebase reference anonymously.
100+
*
101+
* @param {Object} [options] An object containing optional client arguments, such as configuring
102+
* session persistence.
103+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
104+
*/
84105
authAnonymously: function(options) {
85106
var deferred = this._q.defer();
86107

@@ -89,7 +110,15 @@
89110
return deferred.promise;
90111
},
91112

92-
// Authenticates the Firebase reference with an email/password user.
113+
/**
114+
* Authenticates the Firebase reference with an email/password user.
115+
*
116+
* @param {Object} credentials An object containing email and password attributes corresponding
117+
* to the user account.
118+
* @param {Object} [options] An object containing optional client arguments, such as configuring
119+
* session persistence.
120+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
121+
*/
93122
authWithPassword: function(credentials, options) {
94123
var deferred = this._q.defer();
95124

@@ -98,7 +127,15 @@
98127
return deferred.promise;
99128
},
100129

101-
// Authenticates the Firebase reference with the OAuth popup flow.
130+
/**
131+
* Authenticates the Firebase reference with the OAuth popup flow.
132+
*
133+
* @param {string} provider The unique string identifying the OAuth provider to authenticate
134+
* with, e.g. google.
135+
* @param {Object} [options] An object containing optional client arguments, such as configuring
136+
* session persistence.
137+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
138+
*/
102139
authWithOAuthPopup: function(provider, options) {
103140
var deferred = this._q.defer();
104141

@@ -107,7 +144,15 @@
107144
return deferred.promise;
108145
},
109146

110-
// Authenticates the Firebase reference with the OAuth redirect flow.
147+
/**
148+
* Authenticates the Firebase reference with the OAuth redirect flow.
149+
*
150+
* @param {string} provider The unique string identifying the OAuth provider to authenticate
151+
* with, e.g. google.
152+
* @param {Object} [options] An object containing optional client arguments, such as configuring
153+
* session persistence.
154+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
155+
*/
111156
authWithOAuthRedirect: function(provider, options) {
112157
var deferred = this._q.defer();
113158

@@ -116,7 +161,17 @@
116161
return deferred.promise;
117162
},
118163

119-
// Authenticates the Firebase reference with an OAuth token.
164+
/**
165+
* Authenticates the Firebase reference with an OAuth token.
166+
*
167+
* @param {string} provider The unique string identifying the OAuth provider to authenticate
168+
* with, e.g. google.
169+
* @param {string|Object} credentials Either a string, such as an OAuth 2.0 access token, or an
170+
* Object of key / value pairs, such as a set of OAuth 1.0a credentials.
171+
* @param {Object} [options] An object containing optional client arguments, such as configuring
172+
* session persistence.
173+
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
174+
*/
120175
authWithOAuthToken: function(provider, credentials, options) {
121176
var deferred = this._q.defer();
122177

@@ -125,7 +180,9 @@
125180
return deferred.promise;
126181
},
127182

128-
// Unauthenticates the Firebase reference.
183+
/**
184+
* Unauthenticates the Firebase reference.
185+
*/
129186
unauth: function() {
130187
if (this.getAuth() !== null) {
131188
this._ref.unauth();
@@ -136,9 +193,18 @@
136193
/**************************/
137194
/* Authentication State */
138195
/**************************/
139-
// Asynchronously fires the provided callback with the current authentication data every time
140-
// the authentication data changes. It also fires as soon as the authentication data is
141-
// retrieved from the server.
196+
/**
197+
* Asynchronously fires the provided callback with the current authentication data every time
198+
* the authentication data changes. It also fires as soon as the authentication data is
199+
* retrieved from the server.
200+
*
201+
* @param {function} callback A callback that fires when the client's authenticate state
202+
* changes. If authenticated, the callback will be passed an object containing authentication
203+
* data according to the provider used to authenticate. Otherwise, it will be passed null.
204+
* @param {string} [context] If provided, this object will be used as this when calling your
205+
* callback.
206+
* @return {function} A function which can be used to deregister the provided callback.
207+
*/
142208
onAuth: function(callback, context) {
143209
var self = this;
144210

@@ -150,12 +216,23 @@
150216
};
151217
},
152218

153-
// Synchronously retrieves the current authentication data.
219+
/**
220+
* Synchronously retrieves the current authentication data.
221+
*
222+
* @return {Object} The client's authentication data.
223+
*/
154224
getAuth: function() {
155225
return this._ref.getAuth();
156226
},
157227

158-
// Helper onAuth() callback method for the two router-related methods.
228+
/**
229+
* Helper onAuth() callback method for the two router-related methods.
230+
*
231+
* @param {boolean} rejectIfAuthDataIsNull Determines if the returned promise should be
232+
* resolved or rejected upon an unauthenticated client.
233+
* @return {Promise<Object>} A promise fulfilled with the client's authentication state or
234+
* rejected if the client is unauthenticated and rejectIfAuthDataIsNull is true.
235+
*/
159236
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
160237
var ref = this._ref;
161238
var deferred = this._q.defer();
@@ -178,14 +255,24 @@
178255
return deferred.promise;
179256
},
180257

181-
// Returns a promise which is resolved if the client is authenticated and rejects otherwise.
182-
// This can be used to require that a route has a logged in user.
258+
/**
259+
* Utility method which can be used in a route's resolve() method to require that a route has
260+
* a logged in client.
261+
*
262+
* @returns {Promise<Object>} A promise fulfilled with the client's current authentication
263+
* state or rejected if the client is not authenticated.
264+
*/
183265
requireAuth: function() {
184266
return this._routerMethodOnAuthPromise(true);
185267
},
186268

187-
// Returns a promise which is resolved with the client's current authenticated data. This can
188-
// be used in a route's resolve() method to grab the current authentication data.
269+
/**
270+
* Utility method which can be used in a route's resolve() method to grab the current
271+
* authentication data.
272+
*
273+
* @returns {Promise<Object|null>} A promise fulfilled with the client's current authentication
274+
* state, which will be null if the client is not authenticated.
275+
*/
189276
waitForAuth: function() {
190277
return this._routerMethodOnAuthPromise(false);
191278
},
@@ -194,9 +281,16 @@
194281
/*********************/
195282
/* User Management */
196283
/*********************/
197-
// Creates a new email/password user. Note that this function only creates the user, if you
198-
// wish to log in as the newly created user, call $authWithPassword() after the promise for
199-
// this method has been resolved.
284+
/**
285+
* Creates a new email/password user. Note that this function only creates the user, if you
286+
* wish to log in as the newly created user, call $authWithPassword() after the promise for
287+
* this method has been resolved.
288+
*
289+
* @param {Object|string} emailOrCredentials The email of the user to create or an object
290+
* containing the email and password of the user to create.
291+
* @param {string} [password] The password for the user to create.
292+
* @return {Promise<>} An empty promise fulfilled once the user is created.
293+
*/
200294
createUser: function(emailOrCredentials, password) {
201295
var deferred = this._q.defer();
202296

@@ -220,7 +314,16 @@
220314
return deferred.promise;
221315
},
222316

223-
// Changes the password for an email/password user.
317+
/**
318+
* Changes the password for an email/password user.
319+
*
320+
* @param {Object|string} emailOrCredentials The email of the user whose password is to change
321+
* or an objet containing the email, old password, and new password of the user whose password
322+
* is to change.
323+
* @param {string} [oldPassword] The current password for the user.
324+
* @param {string} [newPassword] The new password for the user.
325+
* @return {Promise<>} An empty promise fulfilled once the password change is complete.
326+
*/
224327
changePassword: function(emailOrCredentials, oldPassword, newPassword) {
225328
var deferred = this._q.defer();
226329

@@ -245,7 +348,14 @@
245348
return deferred.promise;
246349
},
247350

248-
// Removes an email/password user.
351+
/**
352+
* Removes an email/password user.
353+
*
354+
* @param {Object|string} emailOrCredentials The email of the user to remove or an object
355+
* containing the email and password of the user to remove.
356+
* @param {string} [password] The password of the user to remove.
357+
* @return {Promise<>} An empty promise fulfilled once the user is removed.
358+
*/
249359
removeUser: function(emailOrCredentials, password) {
250360
var deferred = this._q.defer();
251361

@@ -269,13 +379,26 @@
269379
return deferred.promise;
270380
},
271381

272-
// Sends a password reset email to an email/password user. [DEPRECATED]
382+
/**
383+
* Sends a password reset email to an email/password user. [DEPRECATED]
384+
*
385+
* @deprecated
386+
* @param {Object|string} emailOrCredentials The email of the user to send a reset password
387+
* email to or an object containing the email of the user to send a reset password email to.
388+
* @return {Promise<>} An empty promise fulfilled once the reset password email is sent.
389+
*/
273390
sendPasswordResetEmail: function(emailOrCredentials) {
274391
console.warn("$sendPasswordResetEmail() has been deprecated in favor of the equivalent $resetPassword().");
275392
return this.resetPassword(emailOrCredentials);
276393
},
277394

278-
// Sends a password reset email to an email/password user.
395+
/**
396+
* Sends a password reset email to an email/password user.
397+
*
398+
* @param {Object|string} emailOrCredentials The email of the user to send a reset password
399+
* email to or an object containing the email of the user to send a reset password email to.
400+
* @return {Promise<>} An empty promise fulfilled once the reset password email is sent.
401+
*/
279402
resetPassword: function(emailOrCredentials) {
280403
var deferred = this._q.defer();
281404

0 commit comments

Comments
 (0)