backendless
Version:
Backendless JavaScript SDK for Node.js and the browser
822 lines (819 loc) • 32.1 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _utils = require("./utils");
var _user = _interopRequireDefault(require("./user"));
var _roles = _interopRequireDefault(require("./roles"));
var _social = _interopRequireDefault(require("./social"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var Users = /*#__PURE__*/function () {
function Users(app) {
(0, _classCallCheck2["default"])(this, Users);
this.app = app;
this.roles = new _roles["default"](this);
this.social = new _social["default"](this);
this.dataStore = this.app.Data.of(_user["default"]);
}
(0, _createClass2["default"])(Users, [{
key: "Utils",
get: function get() {
return _utils.UsersUtils;
}
}, {
key: "register",
value: function () {
var _register = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(user) {
var _this = this;
var clientUserLocale;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
user = _objectSpread({}, user);
if (!user.blUserLocale) {
clientUserLocale = this.Utils.getClientUserLocale();
if (clientUserLocale) {
user.blUserLocale = clientUserLocale;
}
}
return _context.abrupt("return", this.app.request.post({
url: this.app.urls.userRegister(),
data: user
}).then(function (data) {
return _this.dataStore.parseResponse(data);
}));
case 3:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function register(_x) {
return _register.apply(this, arguments);
}
return register;
}()
}, {
key: "login",
value: function () {
var _login2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(_login, password, stayLoggedIn) {
var _this2 = this;
var data;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
data = {};
if (!(typeof _login !== 'string' && typeof _login !== 'number')) {
_context2.next = 3;
break;
}
throw new Error('the first argument must be either a string or a number');
case 3:
if (_login) {
_context2.next = 5;
break;
}
throw new Error('the first argument cannot be an empty value');
case 5:
if (typeof password === 'boolean') {
stayLoggedIn = password;
password = undefined;
}
if (!(typeof _login === 'string' && password === undefined)) {
_context2.next = 10;
break;
}
data.objectId = _login;
_context2.next = 14;
break;
case 10:
if (password) {
_context2.next = 12;
break;
}
throw new Error('the "password" value cannot be an empty value');
case 12:
data.login = _login;
data.password = password;
case 14:
stayLoggedIn = stayLoggedIn === true;
return _context2.abrupt("return", this.app.request.post({
url: this.app.urls.userLogin(),
data: data
}).then(function (data) {
return _this2.setCurrentUser(data, stayLoggedIn);
}));
case 16:
case "end":
return _context2.stop();
}
}, _callee2, this);
}));
function login(_x2, _x3, _x4) {
return _login2.apply(this, arguments);
}
return login;
}()
}, {
key: "loginAsGuest",
value: function () {
var _loginAsGuest = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(stayLoggedIn) {
var _this3 = this;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
stayLoggedIn = stayLoggedIn === true;
return _context3.abrupt("return", this.app.request.post({
url: this.app.urls.guestLogin()
}).then(function (data) {
return _this3.setCurrentUser(data, stayLoggedIn);
}));
case 2:
case "end":
return _context3.stop();
}
}, _callee3, this);
}));
function loginAsGuest(_x5) {
return _loginAsGuest.apply(this, arguments);
}
return loginAsGuest;
}()
}, {
key: "loginWithFacebook",
value: function () {
var _loginWithFacebook = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(fieldsMapping, permissions, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", this.social.loginWithFacebook(fieldsMapping, permissions, stayLoggedIn));
case 1:
case "end":
return _context4.stop();
}
}, _callee4, this);
}));
function loginWithFacebook(_x6, _x7, _x8) {
return _loginWithFacebook.apply(this, arguments);
}
return loginWithFacebook;
}()
}, {
key: "loginWithFacebookSdk",
value: function () {
var _loginWithFacebookSdk = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(accessToken, fieldsMapping, stayLoggedIn, options) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
return _context5.abrupt("return", this.social.loginWithFacebookSdk(accessToken, fieldsMapping, stayLoggedIn, options));
case 1:
case "end":
return _context5.stop();
}
}, _callee5, this);
}));
function loginWithFacebookSdk(_x9, _x10, _x11, _x12) {
return _loginWithFacebookSdk.apply(this, arguments);
}
return loginWithFacebookSdk;
}()
}, {
key: "loginWithGooglePlus",
value: function () {
var _loginWithGooglePlus = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(fieldsMapping, permissions, container, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
return _context6.abrupt("return", this.social.loginWithGooglePlus(fieldsMapping, permissions, container, stayLoggedIn));
case 1:
case "end":
return _context6.stop();
}
}, _callee6, this);
}));
function loginWithGooglePlus(_x13, _x14, _x15, _x16) {
return _loginWithGooglePlus.apply(this, arguments);
}
return loginWithGooglePlus;
}()
}, {
key: "loginWithGooglePlusSdk",
value: function () {
var _loginWithGooglePlusSdk = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(accessToken, fieldsMapping, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
return _context7.abrupt("return", this.social.loginWithGooglePlusSdk(accessToken, fieldsMapping, stayLoggedIn));
case 1:
case "end":
return _context7.stop();
}
}, _callee7, this);
}));
function loginWithGooglePlusSdk(_x17, _x18, _x19) {
return _loginWithGooglePlusSdk.apply(this, arguments);
}
return loginWithGooglePlusSdk;
}()
}, {
key: "loginWithTwitter",
value: function () {
var _loginWithTwitter = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(fieldsMapping, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
return _context8.abrupt("return", this.social.loginWithTwitter(fieldsMapping, stayLoggedIn));
case 1:
case "end":
return _context8.stop();
}
}, _callee8, this);
}));
function loginWithTwitter(_x20, _x21) {
return _loginWithTwitter.apply(this, arguments);
}
return loginWithTwitter;
}()
}, {
key: "loginWithOauth2",
value: function () {
var _loginWithOauth = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(providerCode, accessToken, guestUser, fieldsMapping, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
return _context9.abrupt("return", this.social.loginWithOauth2(providerCode, accessToken, guestUser, fieldsMapping, stayLoggedIn));
case 1:
case "end":
return _context9.stop();
}
}, _callee9, this);
}));
function loginWithOauth2(_x22, _x23, _x24, _x25, _x26) {
return _loginWithOauth.apply(this, arguments);
}
return loginWithOauth2;
}()
}, {
key: "loginWithOauth1",
value: function () {
var _loginWithOauth2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(providerCode, accessToken, accessTokenSecret, guestUser, fieldsMapping, stayLoggedIn) {
return _regenerator["default"].wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
return _context10.abrupt("return", this.social.loginWithOauth1(providerCode, accessToken, accessTokenSecret, guestUser, fieldsMapping, stayLoggedIn));
case 1:
case "end":
return _context10.stop();
}
}, _callee10, this);
}));
function loginWithOauth1(_x27, _x28, _x29, _x30, _x31, _x32) {
return _loginWithOauth2.apply(this, arguments);
}
return loginWithOauth1;
}()
}, {
key: "logout",
value: function () {
var _logout = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11() {
var _this4 = this;
return _regenerator["default"].wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
return _context11.abrupt("return", this.app.request.get({
url: this.app.urls.userLogout()
}).then(function () {
_this4.setCurrentUser(null);
})["catch"](function (error) {
if ([3023, 3064, 3090, 3091].includes(error.code)) {
_this4.setCurrentUser(null);
}
throw error;
}));
case 1:
case "end":
return _context11.stop();
}
}, _callee11, this);
}));
function logout() {
return _logout.apply(this, arguments);
}
return logout;
}()
}, {
key: "getCurrentUser",
value: function () {
var _getCurrentUser = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(reload) {
var _this5 = this;
var currentUserId;
return _regenerator["default"].wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
if (!(this.currentUser && !reload)) {
_context12.next = 2;
break;
}
return _context12.abrupt("return", this.currentUser);
case 2:
if (!this.currentUserRequest) {
_context12.next = 4;
break;
}
return _context12.abrupt("return", this.currentUserRequest);
case 4:
currentUserId = this.getCurrentUserId();
if (!currentUserId) {
_context12.next = 7;
break;
}
return _context12.abrupt("return", this.currentUserRequest = this.dataStore.findById(currentUserId).then(function (user) {
_this5.currentUserRequest = null;
user['user-token'] = _this5.currentUser && _this5.currentUser['user-token'] || undefined;
return _this5.currentUser = user;
})["catch"](function (error) {
_this5.currentUserRequest = null;
throw error;
}));
case 7:
return _context12.abrupt("return", null);
case 8:
case "end":
return _context12.stop();
}
}, _callee12, this);
}));
function getCurrentUser(_x33) {
return _getCurrentUser.apply(this, arguments);
}
return getCurrentUser;
}()
}, {
key: "setCurrentUser",
value: function setCurrentUser(user, stayLoggedIn) {
this.app.LocalCache.remove(this.app.LocalCache.Keys.USER_TOKEN);
this.app.LocalCache.remove(this.app.LocalCache.Keys.CURRENT_USER_ID);
this.app.LocalCache.remove(this.app.LocalCache.Keys.STAY_LOGGED_IN);
this.currentUser = user || null;
if (this.currentUser) {
if (!(this.currentUser instanceof _user["default"])) {
this.currentUser = this.dataStore.parseResponse(this.currentUser);
}
if (stayLoggedIn) {
this.app.LocalCache.set(this.app.LocalCache.Keys.STAY_LOGGED_IN, true);
this.app.LocalCache.set(this.app.LocalCache.Keys.USER_TOKEN, this.currentUser['user-token']);
this.app.LocalCache.set(this.app.LocalCache.Keys.CURRENT_USER_ID, this.currentUser.objectId);
}
}
if (this.app.__RT) {
this.app.RT.updateUserTokenIfNeeded();
}
return this.currentUser;
}
}, {
key: "isValidLogin",
value: function () {
var _isValidLogin = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
var userToken;
return _regenerator["default"].wrap(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
userToken = this.getCurrentUserToken();
if (!userToken) {
_context13.next = 3;
break;
}
return _context13.abrupt("return", this.app.request.get({
url: this.app.urls.userTokenCheck(userToken)
}));
case 3:
return _context13.abrupt("return", false);
case 4:
case "end":
return _context13.stop();
}
}, _callee13, this);
}));
function isValidLogin() {
return _isValidLogin.apply(this, arguments);
}
return isValidLogin;
}()
}, {
key: "verifyPassword",
value: function () {
var _verifyPassword = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(currentPassword) {
return _regenerator["default"].wrap(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
if (!(!currentPassword || typeof currentPassword !== 'string')) {
_context14.next = 2;
break;
}
throw new Error('Password has to be a non empty string');
case 2:
if (this.getCurrentUserToken()) {
_context14.next = 4;
break;
}
throw new Error('In order to check password you have to be logged in');
case 4:
return _context14.abrupt("return", this.app.request.post({
url: this.app.urls.userVerifyPassowrd(),
data: {
password: currentPassword
}
}).then(function (result) {
return !!(result && result.valid);
}));
case 5:
case "end":
return _context14.stop();
}
}, _callee14, this);
}));
function verifyPassword(_x34) {
return _verifyPassword.apply(this, arguments);
}
return verifyPassword;
}()
}, {
key: "restorePassword",
value: function () {
var _restorePassword = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(emailAddress) {
return _regenerator["default"].wrap(function _callee15$(_context15) {
while (1) switch (_context15.prev = _context15.next) {
case 0:
if (!(!emailAddress || typeof emailAddress !== 'string')) {
_context15.next = 2;
break;
}
throw new Error('Email Address must be provided and must be a string.');
case 2:
return _context15.abrupt("return", this.app.request.get({
url: this.app.urls.userRestorePassword(emailAddress)
}));
case 3:
case "end":
return _context15.stop();
}
}, _callee15, this);
}));
function restorePassword(_x35) {
return _restorePassword.apply(this, arguments);
}
return restorePassword;
}()
}, {
key: "resendEmailConfirmation",
value: function () {
var _resendEmailConfirmation = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(identity) {
return _regenerator["default"].wrap(function _callee16$(_context16) {
while (1) switch (_context16.prev = _context16.next) {
case 0:
if (!(typeof identity === 'string')) {
_context16.next = 5;
break;
}
if (identity) {
_context16.next = 3;
break;
}
throw new Error('Identity can not be an empty string.');
case 3:
_context16.next = 7;
break;
case 5:
if (!(typeof identity !== 'number')) {
_context16.next = 7;
break;
}
throw new Error('Identity must be a string or number.');
case 7:
return _context16.abrupt("return", this.app.request.post({
url: this.app.urls.userResendConfirmation(identity)
}));
case 8:
case "end":
return _context16.stop();
}
}, _callee16, this);
}));
function resendEmailConfirmation(_x36) {
return _resendEmailConfirmation.apply(this, arguments);
}
return resendEmailConfirmation;
}()
}, {
key: "createEmailConfirmationURL",
value: function () {
var _createEmailConfirmationURL = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(identity) {
return _regenerator["default"].wrap(function _callee17$(_context17) {
while (1) switch (_context17.prev = _context17.next) {
case 0:
if (!(typeof identity === 'string')) {
_context17.next = 5;
break;
}
if (identity) {
_context17.next = 3;
break;
}
throw new Error('Identity can not be an empty string.');
case 3:
_context17.next = 7;
break;
case 5:
if (!(typeof identity !== 'number')) {
_context17.next = 7;
break;
}
throw new Error('Identity must be a string or number.');
case 7:
return _context17.abrupt("return", this.app.request.post({
url: this.app.urls.userCreateConfirmationURL(identity)
}));
case 8:
case "end":
return _context17.stop();
}
}, _callee17, this);
}));
function createEmailConfirmationURL(_x37) {
return _createEmailConfirmationURL.apply(this, arguments);
}
return createEmailConfirmationURL;
}()
}, {
key: "update",
value: function () {
var _update = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(user) {
var _this6 = this;
return _regenerator["default"].wrap(function _callee18$(_context18) {
while (1) switch (_context18.prev = _context18.next) {
case 0:
return _context18.abrupt("return", this.app.request.put({
url: this.app.urls.userObject(user.objectId),
data: user
}).then(function (data) {
return _this6.dataStore.parseResponse(data);
}));
case 1:
case "end":
return _context18.stop();
}
}, _callee18, this);
}));
function update(_x38) {
return _update.apply(this, arguments);
}
return update;
}()
}, {
key: "findByRole",
value: function () {
var _findByRole = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(roleName, loadRoles, query) {
return _regenerator["default"].wrap(function _callee19$(_context19) {
while (1) switch (_context19.prev = _context19.next) {
case 0:
return _context19.abrupt("return", this.roles.findByRole(roleName, loadRoles, query));
case 1:
case "end":
return _context19.stop();
}
}, _callee19, this);
}));
function findByRole(_x39, _x40, _x41) {
return _findByRole.apply(this, arguments);
}
return findByRole;
}()
}, {
key: "getUserRoles",
value: function () {
var _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(userId) {
return _regenerator["default"].wrap(function _callee20$(_context20) {
while (1) switch (_context20.prev = _context20.next) {
case 0:
return _context20.abrupt("return", this.roles.getUserRoles(userId));
case 1:
case "end":
return _context20.stop();
}
}, _callee20, this);
}));
function getUserRoles(_x42) {
return _getUserRoles.apply(this, arguments);
}
return getUserRoles;
}()
}, {
key: "assignRole",
value: function () {
var _assignRole = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21(identity, rolename) {
return _regenerator["default"].wrap(function _callee21$(_context21) {
while (1) switch (_context21.prev = _context21.next) {
case 0:
return _context21.abrupt("return", this.roles.assignRole(identity, rolename));
case 1:
case "end":
return _context21.stop();
}
}, _callee21, this);
}));
function assignRole(_x43, _x44) {
return _assignRole.apply(this, arguments);
}
return assignRole;
}()
}, {
key: "unassignRole",
value: function () {
var _unassignRole = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee22(identity, rolename) {
return _regenerator["default"].wrap(function _callee22$(_context22) {
while (1) switch (_context22.prev = _context22.next) {
case 0:
return _context22.abrupt("return", this.roles.unassignRole(identity, rolename));
case 1:
case "end":
return _context22.stop();
}
}, _callee22, this);
}));
function unassignRole(_x45, _x46) {
return _unassignRole.apply(this, arguments);
}
return unassignRole;
}()
}, {
key: "describeUserClass",
value: function () {
var _describeUserClass = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee23() {
return _regenerator["default"].wrap(function _callee23$(_context23) {
while (1) switch (_context23.prev = _context23.next) {
case 0:
return _context23.abrupt("return", this.app.request.get({
url: this.app.urls.userClassProps()
}));
case 1:
case "end":
return _context23.stop();
}
}, _callee23, this);
}));
function describeUserClass() {
return _describeUserClass.apply(this, arguments);
}
return describeUserClass;
}()
}, {
key: "enableUser",
value: function () {
var _enableUser = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(userId) {
return _regenerator["default"].wrap(function _callee24$(_context24) {
while (1) switch (_context24.prev = _context24.next) {
case 0:
return _context24.abrupt("return", this.updateUserStatus(userId, 'ENABLED'));
case 1:
case "end":
return _context24.stop();
}
}, _callee24, this);
}));
function enableUser(_x47) {
return _enableUser.apply(this, arguments);
}
return enableUser;
}()
}, {
key: "disableUser",
value: function () {
var _disableUser = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee25(userId) {
return _regenerator["default"].wrap(function _callee25$(_context25) {
while (1) switch (_context25.prev = _context25.next) {
case 0:
return _context25.abrupt("return", this.updateUserStatus(userId, 'DISABLED'));
case 1:
case "end":
return _context25.stop();
}
}, _callee25, this);
}));
function disableUser(_x48) {
return _disableUser.apply(this, arguments);
}
return disableUser;
}()
}, {
key: "updateUserStatus",
value: function () {
var _updateUserStatus = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee26(userId, userStatus) {
return _regenerator["default"].wrap(function _callee26$(_context26) {
while (1) switch (_context26.prev = _context26.next) {
case 0:
if (!(!userId || typeof userId !== 'string' && typeof userId !== 'number')) {
_context26.next = 2;
break;
}
throw new Error('User objectId must be non empty string/number');
case 2:
if (!(!userStatus || typeof userStatus !== 'string')) {
_context26.next = 4;
break;
}
throw new Error('User Status must be a valid string');
case 4:
return _context26.abrupt("return", this.app.request.put({
url: this.app.urls.userStatus(userId),
data: {
userStatus: userStatus
}
}));
case 5:
case "end":
return _context26.stop();
}
}, _callee26, this);
}));
function updateUserStatus(_x49, _x50) {
return _updateUserStatus.apply(this, arguments);
}
return updateUserStatus;
}()
}, {
key: "getAuthorizationUrlLink",
value: function getAuthorizationUrlLink(providerCode, fieldsMapping, scope, redirect, redirectAfterLoginUrl, callbackUrlDomain) {
return this.app.request.post({
url: this.app.urls.userAuthorizationURL(providerCode),
data: {
fieldsMapping: fieldsMapping,
permissions: scope,
redirect: redirect,
redirectAfterLoginUrl: redirectAfterLoginUrl,
callbackUrlDomain: callbackUrlDomain
}
});
}
}, {
key: "loggedInUser",
value: function loggedInUser() {
return this.getCurrentUserId();
}
}, {
key: "getCurrentUserToken",
value: function getCurrentUserToken() {
if (this.currentUser && this.currentUser['user-token']) {
return this.currentUser['user-token'];
}
return this.app.LocalCache.get(this.app.LocalCache.Keys.USER_TOKEN) || null;
}
}, {
key: "setCurrentUserToken",
value: function setCurrentUserToken(userToken) {
userToken = userToken || null;
if (this.currentUser) {
this.currentUser['user-token'] = userToken;
}
if (this.app.LocalCache.get('user-token')) {
this.app.LocalCache.set('user-token', userToken);
}
if (this.app.__RT) {
this.app.RT.updateUserTokenIfNeeded();
}
}
}, {
key: "getCurrentUserId",
value: function getCurrentUserId() {
if (this.currentUser) {
return this.currentUser.objectId;
}
return this.app.LocalCache.get(this.app.LocalCache.Keys.CURRENT_USER_ID) || null;
}
/**
* @deprecated
* */
}, {
key: "getLocalCurrentUser",
value: function getLocalCurrentUser() {
return this.currentUser;
}
/**
* @deprecated
* */
}, {
key: "setLocalCurrentUser",
value: function setLocalCurrentUser(user, stayLoggedIn) {
return this.setCurrentUser(user, stayLoggedIn);
}
}]);
return Users;
}();
exports["default"] = Users;