|
62 | 62 | /********************/ |
63 | 63 | /* Authentication */ |
64 | 64 | /********************/ |
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 | + */ |
66 | 72 | _onLoginHandler: function(deferred, error, authData) { |
67 | 73 | if (error !== null) { |
68 | 74 | deferred.reject(error); |
|
71 | 77 | } |
72 | 78 | }, |
73 | 79 |
|
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 | + */ |
75 | 90 | authWithCustomToken: function(authToken, options) { |
76 | 91 | var deferred = this._q.defer(); |
77 | 92 |
|
|
80 | 95 | return deferred.promise; |
81 | 96 | }, |
82 | 97 |
|
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 | + */ |
84 | 105 | authAnonymously: function(options) { |
85 | 106 | var deferred = this._q.defer(); |
86 | 107 |
|
|
89 | 110 | return deferred.promise; |
90 | 111 | }, |
91 | 112 |
|
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 | + */ |
93 | 122 | authWithPassword: function(credentials, options) { |
94 | 123 | var deferred = this._q.defer(); |
95 | 124 |
|
|
98 | 127 | return deferred.promise; |
99 | 128 | }, |
100 | 129 |
|
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 | + */ |
102 | 139 | authWithOAuthPopup: function(provider, options) { |
103 | 140 | var deferred = this._q.defer(); |
104 | 141 |
|
|
107 | 144 | return deferred.promise; |
108 | 145 | }, |
109 | 146 |
|
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 | + */ |
111 | 156 | authWithOAuthRedirect: function(provider, options) { |
112 | 157 | var deferred = this._q.defer(); |
113 | 158 |
|
|
116 | 161 | return deferred.promise; |
117 | 162 | }, |
118 | 163 |
|
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 | + */ |
120 | 175 | authWithOAuthToken: function(provider, credentials, options) { |
121 | 176 | var deferred = this._q.defer(); |
122 | 177 |
|
|
125 | 180 | return deferred.promise; |
126 | 181 | }, |
127 | 182 |
|
128 | | - // Unauthenticates the Firebase reference. |
| 183 | + /** |
| 184 | + * Unauthenticates the Firebase reference. |
| 185 | + */ |
129 | 186 | unauth: function() { |
130 | 187 | if (this.getAuth() !== null) { |
131 | 188 | this._ref.unauth(); |
|
136 | 193 | /**************************/ |
137 | 194 | /* Authentication State */ |
138 | 195 | /**************************/ |
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 | + */ |
142 | 208 | onAuth: function(callback, context) { |
143 | 209 | var self = this; |
144 | 210 |
|
|
150 | 216 | }; |
151 | 217 | }, |
152 | 218 |
|
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 | + */ |
154 | 224 | getAuth: function() { |
155 | 225 | return this._ref.getAuth(); |
156 | 226 | }, |
157 | 227 |
|
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 | + */ |
159 | 236 | _routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) { |
160 | 237 | var ref = this._ref; |
161 | 238 | var deferred = this._q.defer(); |
|
178 | 255 | return deferred.promise; |
179 | 256 | }, |
180 | 257 |
|
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 | + */ |
183 | 265 | requireAuth: function() { |
184 | 266 | return this._routerMethodOnAuthPromise(true); |
185 | 267 | }, |
186 | 268 |
|
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 | + */ |
189 | 276 | waitForAuth: function() { |
190 | 277 | return this._routerMethodOnAuthPromise(false); |
191 | 278 | }, |
|
194 | 281 | /*********************/ |
195 | 282 | /* User Management */ |
196 | 283 | /*********************/ |
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 | + */ |
200 | 294 | createUser: function(emailOrCredentials, password) { |
201 | 295 | var deferred = this._q.defer(); |
202 | 296 |
|
|
220 | 314 | return deferred.promise; |
221 | 315 | }, |
222 | 316 |
|
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 | + */ |
224 | 327 | changePassword: function(emailOrCredentials, oldPassword, newPassword) { |
225 | 328 | var deferred = this._q.defer(); |
226 | 329 |
|
|
245 | 348 | return deferred.promise; |
246 | 349 | }, |
247 | 350 |
|
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 | + */ |
249 | 359 | removeUser: function(emailOrCredentials, password) { |
250 | 360 | var deferred = this._q.defer(); |
251 | 361 |
|
|
269 | 379 | return deferred.promise; |
270 | 380 | }, |
271 | 381 |
|
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 | + */ |
273 | 390 | sendPasswordResetEmail: function(emailOrCredentials) { |
274 | 391 | console.warn("$sendPasswordResetEmail() has been deprecated in favor of the equivalent $resetPassword()."); |
275 | 392 | return this.resetPassword(emailOrCredentials); |
276 | 393 | }, |
277 | 394 |
|
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 | + */ |
279 | 402 | resetPassword: function(emailOrCredentials) { |
280 | 403 | var deferred = this._q.defer(); |
281 | 404 |
|
|
0 commit comments