Repository URL to install this package:
|
Version:
0.4.8 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fetchEverywhere = require('fetch-everywhere');
var _fetchEverywhere2 = _interopRequireDefault(_fetchEverywhere);
var _fetch = require('../../helpers/fetch.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var path = '/api/users';
var API = {
me: function me(token, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/me', {
headers: {
Accept: 'application/json',
'Access-Token': token
}
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
tokenFromCookie: function tokenFromCookie(cookie, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/access-token-from-cookie', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(cookie)
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
login: function login(email, password, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/oauth/token', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: email, password: password })
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
signup: function signup(name, email, password, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: name, email: email, password: password })
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
resendActivation: function resendActivation(email, password, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/resend-activation', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: email, password: password })
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
requestPasswordResetEmail: function requestPasswordResetEmail(email, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/request-password-reset-email', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: email })
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
googleCodeForLogin: function googleCodeForLogin(code, locale, options) {
var state = {
is_mobile: 'false',
redirect_uri: '/', // this is for the OAuth web/server flow (which we don't use, but it's a necessary param on our API)
callbackUrl: options.googleRedirectUri, // this is for the OAuth web/server flow (which we don't use, but it's a necessary param on our API)
locale: locale
};
return (0, _fetchEverywhere2.default)((options.url || path) + '/google-code-for-login?code=' + code + '&state=' + encodeURIComponent(JSON.stringify(state)), {
method: 'GET',
headers: {
Accept: 'application/json'
}
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
loginOrSignupWithGoogle: function loginOrSignupWithGoogle(accessToken, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/oauth/google', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: encodeURIComponent('google_access_token') + '=' + encodeURIComponent(accessToken)
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
loginOrSignupWithFacebook: function loginOrSignupWithFacebook(accessToken, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/oauth/facebook', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: encodeURIComponent('facebook_access_token') + '=' + encodeURIComponent(accessToken)
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
},
getLoggedInCookie: function getLoggedInCookie(accessToken, options) {
return (0, _fetchEverywhere2.default)((options.url || path) + '/me/cookie-from-access-token', {
method: 'GET',
headers: {
'Access-Token': accessToken
},
credentials: 'include'
}).catch(_fetch.errorHandler).then(_fetch.responseHandler);
}
};
exports.default = API;