jinaga
Version:
Data management for web and mobile applications.
64 lines • 2.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationOffline = void 0;
class AuthenticationOffline {
constructor(store, client) {
this.store = store;
this.client = client;
}
login() {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield this.loginRemote();
}
catch (err) {
if (err === 'Unauthorized') {
throw err;
}
try {
return yield this.loginLocal();
}
catch (err2) {
throw err;
}
}
});
}
local() {
throw new Error('Local device has no persistence.');
}
authorize(envelopes) {
return Promise.resolve(envelopes);
}
loginRemote() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.client.login();
if (result && result.userFact && result.profile) {
yield this.store.saveLogin('token', result.userFact, result.profile.displayName);
}
return result;
});
}
loginLocal() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.store.loadLogin('token');
return {
userFact: result.userFact,
profile: {
displayName: result.displayName
}
};
});
}
}
exports.AuthenticationOffline = AuthenticationOffline;
//# sourceMappingURL=authentication-offline.js.map