Commit c91fc26c authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v0.0.18

parent 93dff9e9
...@@ -5,9 +5,28 @@ function * checkSessionToken(next) { ...@@ -5,9 +5,28 @@ function * checkSessionToken(next) {
this.throwResponseErrorIfNeed(this.errors); this.throwResponseErrorIfNeed(this.errors);
this.state.sessionToken = sessionToken; const user = yield * fetchUser.apply(this);
this.throwResponseErrorIfNeed(!user, 'session token is invalid');
this.logger.log(__filename, 'user', user);
this.state.user = user;
yield next; yield next;
} }
function * fetchUser() {
const url = urlJoin(
this.state.instance.auth_endpoint, 'p', this.state.project.id, 'sessions',
`${this.state.sessionToken}?service_id=${this.config.service.id}`
);
this.logger.log(__filename, 'fetch user url:', url);
yield fetch(url)
.then(res => res.json())
.then(user => Object.assign(user, {sessionToken: this.state.sessionToken}));
}
module.exports = checkSessionToken; module.exports = checkSessionToken;
{ {
"name": "service-sdk", "name": "service-sdk",
"version": "0.0.17", "version": "0.0.18",
"private": true, "private": true,
"description": "Service SDK for LViS", "description": "Service SDK for LViS",
"keywords": [], "keywords": [],
......
...@@ -10,12 +10,8 @@ function * getProject() { ...@@ -10,12 +10,8 @@ function * getProject() {
return; return;
} }
const user = yield * fetchUser.apply(this);
this.logger.log(__filename, 'user', user);
this.body = yield this.config.projectTabCallback( this.body = yield this.config.projectTabCallback(
this.state.instance, this.state.project, this.state.tabId, user this.state.instance, this.state.project, this.state.tabId, this.state.user
); );
} }
...@@ -26,26 +22,9 @@ function * getEvent() { ...@@ -26,26 +22,9 @@ function * getEvent() {
return; return;
} }
const user = yield * fetchUser.apply(this);
this.logger.log(__filename, 'user', user);
this.body = yield this.config.projectTabCallback( this.body = yield this.config.projectTabCallback(
this.state.instance, this.state.project, this.state.eventId, this.state.tabId, user this.state.instance, this.state.project, this.state.eventId, this.state.tabId, this.state.user
); );
} }
module.exports = {getProject, getEvent}; module.exports = {getProject, getEvent};
function * fetchUser() {
const url = urlJoin(
this.state.instance.auth_endpoint, 'p', this.state.project.id, 'sessions',
`${this.config.service.id}?service_id=${this.state.sessionToken}`
);
this.logger.log(__filename, 'fetch user url:', url);
yield fetch(url)
.then(res => res.json())
.then(user => Object.assign(user, {sessionToken: this.state.sessionToken}));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment