curtain-web-api 1.0.30 → 1.0.31

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.
@@ -136,10 +136,8 @@ class CurtainWebAPI {
136
136
  headers["Content-Type"] = "application/json";
137
137
  headers["withCredentials"] = "true";
138
138
  return this.axiosInstance.post(this.loginURL, { username, password }, { headers: headers, responseType: "json" }).then((response) => {
139
- this.user.access_token = response.data.access;
140
- this.user.refresh_token = response.data.refresh;
141
139
  this.user.loginStatus = true;
142
- return this.user.saveIntoDB().then((response) => {
140
+ return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
143
141
  return this.getUserInfo();
144
142
  });
145
143
  });
@@ -148,6 +146,7 @@ class CurtainWebAPI {
148
146
  const headers = new axios_1.AxiosHeaders();
149
147
  headers["Accept"] = "application/json";
150
148
  headers["Content-Type"] = "application/json";
149
+ console.log(this.user);
151
150
  return this.axiosInstance.post(this.userInfoURL, {}, { headers: headers, responseType: "json" }).then((response) => {
152
151
  this.user.canDelete = response.data.can_delete;
153
152
  this.user.id = response.data.id;
@@ -186,11 +185,7 @@ class CurtainWebAPI {
186
185
  headers["Accept"] = "application/json";
187
186
  headers["Content-Type"] = "application/json";
188
187
  return this.axiosInstance.post(this.orcidLoginURL, JSON.stringify({ "auth_token": authorizationCode, "redirect_uri": redirectURI }), { headers: headers, responseType: "json" }).then((response) => {
189
- this.user.access_token = response.data.access;
190
- this.user.refresh_token = response.data.refresh;
191
- this.user.loginStatus = true;
192
- console.log(this.user.loginStatus);
193
- return this.user.saveIntoDB().then((response) => {
188
+ return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
194
189
  return this.getUserInfo();
195
190
  });
196
191
  });
@@ -24,7 +24,7 @@ export declare class User {
24
24
  init(): Promise<void | undefined>;
25
25
  initiateDB(): Promise<void>;
26
26
  updateDB(): Promise<void>;
27
- saveIntoDB(): Promise<PouchDB.Core.Response>;
27
+ saveIntoDB(accessToken: string, refreshToken: string): Promise<PouchDB.Core.Response>;
28
28
  loadFromDB(): Promise<void>;
29
29
  clearDB(): Promise<void>;
30
30
  reset(): void;
@@ -86,15 +86,16 @@ class User {
86
86
  console.log(error);
87
87
  });
88
88
  }
89
- saveIntoDB() {
90
- console.log(this.loginStatus);
89
+ saveIntoDB(accessToken, refreshToken) {
90
+ this.access_token = accessToken;
91
+ this.refresh_token = refreshToken;
92
+ this.loginStatus = true;
91
93
  return this.db.get("user").catch((error) => {
92
94
  if (error.name === "not_found") {
93
- console.log(this.loginStatus);
94
95
  return {
95
96
  _id: "user",
96
- access_token: this.access_token,
97
- refresh_token: this.refresh_token,
97
+ access_token: accessToken,
98
+ refresh_token: refreshToken,
98
99
  username: this.username,
99
100
  loginStatus: true,
100
101
  isStaff: this.isStaff,
@@ -111,12 +112,11 @@ class User {
111
112
  throw error;
112
113
  }
113
114
  }).then((doc) => {
114
- console.log(this.loginStatus);
115
115
  return this.db.put({
116
116
  _id: "user",
117
117
  _rev: doc._rev,
118
- access_token: this.access_token,
119
- refresh_token: this.refresh_token,
118
+ access_token: accessToken,
119
+ refresh_token: refreshToken,
120
120
  username: this.username,
121
121
  loginStatus: true,
122
122
  isStaff: this.isStaff,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -114,10 +114,8 @@ export class CurtainWebAPI {
114
114
  headers["Content-Type"] = "application/json";
115
115
  headers["withCredentials"] = "true";
116
116
  return this.axiosInstance.post(this.loginURL, {username, password}, {headers: headers, responseType:"json"}).then((response) => {
117
- this.user.access_token = response.data.access;
118
- this.user.refresh_token = response.data.refresh;
119
117
  this.user.loginStatus = true;
120
- return this.user.saveIntoDB().then((response) => {
118
+ return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
121
119
  return this.getUserInfo()
122
120
  })
123
121
  });
@@ -127,7 +125,7 @@ export class CurtainWebAPI {
127
125
  const headers = new AxiosHeaders();
128
126
  headers["Accept"] = "application/json";
129
127
  headers["Content-Type"] = "application/json";
130
-
128
+ console.log(this.user)
131
129
  return this.axiosInstance.post(this.userInfoURL, {}, {headers: headers, responseType: "json"}).then((response) => {
132
130
  this.user.canDelete = response.data.can_delete;
133
131
  this.user.id = response.data.id;
@@ -170,11 +168,7 @@ export class CurtainWebAPI {
170
168
  headers["Accept"] = "application/json";
171
169
  headers["Content-Type"] = "application/json";
172
170
  return this.axiosInstance.post(this.orcidLoginURL, JSON.stringify({"auth_token": authorizationCode, "redirect_uri": redirectURI}), {headers: headers, responseType:"json"}).then((response) => {
173
- this.user.access_token = response.data.access;
174
- this.user.refresh_token = response.data.refresh;
175
- this.user.loginStatus = true;
176
- console.log(this.user.loginStatus)
177
- return this.user.saveIntoDB().then((response) => {
171
+ return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
178
172
  return this.getUserInfo()
179
173
  })
180
174
  })
@@ -94,15 +94,16 @@ export class User {
94
94
  });
95
95
  }
96
96
 
97
- saveIntoDB() {
98
- console.log(this.loginStatus)
97
+ saveIntoDB(accessToken: string, refreshToken: string) {
98
+ this.access_token = accessToken;
99
+ this.refresh_token = refreshToken;
100
+ this.loginStatus = true;
99
101
  return this.db.get("user").catch((error) => {
100
102
  if (error.name === "not_found") {
101
- console.log(this.loginStatus)
102
103
  return {
103
104
  _id: "user",
104
- access_token: this.access_token,
105
- refresh_token: this.refresh_token,
105
+ access_token: accessToken,
106
+ refresh_token: refreshToken,
106
107
  username: this.username,
107
108
  loginStatus: true,
108
109
  isStaff: this.isStaff,
@@ -118,12 +119,11 @@ export class User {
118
119
  throw error
119
120
  }
120
121
  }).then((doc: any) => {
121
- console.log(this.loginStatus)
122
122
  return this.db.put({
123
123
  _id: "user",
124
124
  _rev: doc._rev,
125
- access_token: this.access_token,
126
- refresh_token: this.refresh_token,
125
+ access_token: accessToken,
126
+ refresh_token: refreshToken,
127
127
  username: this.username,
128
128
  loginStatus: true,
129
129
  isStaff: this.isStaff,