pryv 3.6.1 → 3.7.1
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.
- package/package.json +1 -1
- package/src/Service.js +12 -1
package/package.json
CHANGED
package/src/Service.js
CHANGED
|
@@ -285,6 +285,12 @@ class Service {
|
|
|
285
285
|
* Resolve an email address to a username on this service.
|
|
286
286
|
* One round-trip via `GET <register>/<email>/uid`.
|
|
287
287
|
*
|
|
288
|
+
* On multi-core services where the platform stores identifiers hashed,
|
|
289
|
+
* the queried node may not host the user and answers `307` with the
|
|
290
|
+
* home node's URL in `{ server }`. `fetch` follows the redirect
|
|
291
|
+
* transparently; for HTTP clients that do not auto-follow, this method
|
|
292
|
+
* also follows the `{ server }` hint once explicitly.
|
|
293
|
+
*
|
|
288
294
|
* @param {string} email - The email to look up
|
|
289
295
|
* @returns {Promise<string|null>} The username, or `null` if unknown
|
|
290
296
|
* @throws {PryvError} on network errors or non-404 API errors
|
|
@@ -292,7 +298,12 @@ class Service {
|
|
|
292
298
|
async userIdForEmail (email) {
|
|
293
299
|
const serviceInfo = await this.info();
|
|
294
300
|
const url = serviceInfo.register + encodeURIComponent(email) + '/uid';
|
|
295
|
-
|
|
301
|
+
let { response, body } = await utils.fetchGet(url);
|
|
302
|
+
if (response.status === 307 && body && body.server) {
|
|
303
|
+
const home = body.server.endsWith('/') ? body.server : body.server + '/';
|
|
304
|
+
const homeUrl = home + 'reg/' + encodeURIComponent(email) + '/uid';
|
|
305
|
+
({ response, body } = await utils.fetchGet(homeUrl));
|
|
306
|
+
}
|
|
296
307
|
if (response.ok) return (body && (body.uid || body.username)) || null;
|
|
297
308
|
if (response.status === 404) return null;
|
|
298
309
|
throw PryvError.fromApiResponse(response, body);
|