@steroidsjs/core 2.3.0-beta.3 → 2.3.0-beta.4
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.
package/actions/auth.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const AUTH_SET_DATA = "AUTH_SET_DATA";
|
|
|
4
4
|
export declare const AUTH_ADD_SOCIAL = "AUTH_ADD_SOCIAL";
|
|
5
5
|
export declare const init: (skipInitialized?: boolean) => (dispatch: any, getState: any) => any;
|
|
6
6
|
export declare const reInit: () => (dispatch: any, getState: any) => any;
|
|
7
|
-
export declare const login: (token: any, redirectPageId?: string | boolean) => (dispatch: any, getState: any, { http }: {
|
|
7
|
+
export declare const login: (token: any, redirectPageId?: string | boolean, params?: any) => (dispatch: any, getState: any, { http }: {
|
|
8
8
|
http: any;
|
|
9
9
|
}) => any;
|
|
10
10
|
export declare const addSocial: (social: any) => {
|
package/actions/auth.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
exports.__esModule = true;
|
|
3
14
|
exports.logout = exports.setData = exports.setUser = exports.addSocial = exports.login = exports.reInit = exports.init = exports.AUTH_ADD_SOCIAL = exports.AUTH_SET_DATA = exports.AUTH_INIT_USER = exports.AUTH_INIT = void 0;
|
|
4
15
|
var router_1 = require("./router");
|
|
@@ -23,11 +34,11 @@ var init = function (skipInitialized) {
|
|
|
23
34
|
exports.init = init;
|
|
24
35
|
var reInit = function () { return exports.init(); };
|
|
25
36
|
exports.reInit = reInit;
|
|
26
|
-
var login = function (token, redirectPageId) {
|
|
37
|
+
var login = function (token, redirectPageId, params) {
|
|
27
38
|
if (redirectPageId === void 0) { redirectPageId = 'root'; }
|
|
28
39
|
return function (dispatch, getState, _a) {
|
|
29
40
|
var http = _a.http;
|
|
30
|
-
http.
|
|
41
|
+
http.onLogin(__assign({ accessToken: token }, params));
|
|
31
42
|
return dispatch({
|
|
32
43
|
type: exports.AUTH_INIT,
|
|
33
44
|
redirectPageId: redirectPageId || null
|
|
@@ -36,6 +36,9 @@ export default class HttpComponent {
|
|
|
36
36
|
getAccessToken(): Promise<any>;
|
|
37
37
|
resetConfig(): void;
|
|
38
38
|
onLogout(): void;
|
|
39
|
+
onLogin(params: {
|
|
40
|
+
accessToken: string;
|
|
41
|
+
}): void;
|
|
39
42
|
getAxiosInstance(): Promise<any>;
|
|
40
43
|
getUrl(method: any): any;
|
|
41
44
|
get(url: any, params?: {}, options?: IHttpRequestOptions): any;
|
|
@@ -176,6 +176,9 @@ var HttpComponent = /** @class */ (function () {
|
|
|
176
176
|
HttpComponent.prototype.onLogout = function () {
|
|
177
177
|
this.removeAccessToken();
|
|
178
178
|
};
|
|
179
|
+
HttpComponent.prototype.onLogin = function (params) {
|
|
180
|
+
this.setAccessToken(params.accessToken);
|
|
181
|
+
};
|
|
179
182
|
HttpComponent.prototype.getAxiosInstance = function () {
|
|
180
183
|
return __awaiter(this, void 0, void 0, function () {
|
|
181
184
|
var _a, _b, _c;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BaseHttpComponent from '
|
|
1
|
+
import BaseHttpComponent from './HttpComponent';
|
|
2
2
|
export default class JwtHttpComponent extends BaseHttpComponent {
|
|
3
3
|
refreshTokenRequest: {
|
|
4
4
|
url: string;
|
|
@@ -7,11 +7,18 @@ export default class JwtHttpComponent extends BaseHttpComponent {
|
|
|
7
7
|
refreshTokenKey: string;
|
|
8
8
|
_refreshToken: any;
|
|
9
9
|
constructor(components: any, config?: any);
|
|
10
|
-
getAxiosConfig(): Promise<
|
|
10
|
+
getAxiosConfig(): Promise<{
|
|
11
|
+
withCredentials: boolean;
|
|
12
|
+
headers: any;
|
|
13
|
+
}>;
|
|
11
14
|
private setRefreshTokenInterceptor;
|
|
12
15
|
getAxiosInstance(): Promise<any>;
|
|
13
16
|
removeRefreshToken(): void;
|
|
14
17
|
setRefreshToken(value: any): void;
|
|
15
18
|
getRefreshToken(): Promise<any>;
|
|
16
19
|
onLogout(): void;
|
|
20
|
+
onLogin(params: {
|
|
21
|
+
accessToken: string;
|
|
22
|
+
refreshToken: string;
|
|
23
|
+
}): void;
|
|
17
24
|
}
|
|
@@ -55,10 +55,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
};
|
|
56
56
|
exports.__esModule = true;
|
|
57
57
|
var axios_1 = __importDefault(require("axios"));
|
|
58
|
-
|
|
59
|
-
var HttpComponent_1 = __importDefault(require("
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
var auth_1 = require("@steroidsjs/core/actions/auth");
|
|
58
|
+
var auth_1 = require("../actions/auth");
|
|
59
|
+
var HttpComponent_1 = __importDefault(require("./HttpComponent"));
|
|
62
60
|
var JwtHttpComponent = /** @class */ (function (_super) {
|
|
63
61
|
__extends(JwtHttpComponent, _super);
|
|
64
62
|
function JwtHttpComponent(components, config) {
|
|
@@ -112,6 +110,7 @@ var JwtHttpComponent = /** @class */ (function (_super) {
|
|
|
112
110
|
case 0:
|
|
113
111
|
originalRequest = error.config;
|
|
114
112
|
if (!(error.response.status === 401 && error.config && !error.config._isRetry)) return [3 /*break*/, 2];
|
|
113
|
+
this.removeAccessToken();
|
|
115
114
|
store = this._components.store;
|
|
116
115
|
return [4 /*yield*/, this.send(this.refreshTokenRequest.method, this.refreshTokenRequest.url, (_a = {},
|
|
117
116
|
_a[this.refreshTokenKey] = this._refreshToken,
|
|
@@ -120,14 +119,12 @@ var JwtHttpComponent = /** @class */ (function (_super) {
|
|
|
120
119
|
response = _c.sent();
|
|
121
120
|
accessToken = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b[this.accessTokenKey];
|
|
122
121
|
if (accessToken) {
|
|
123
|
-
|
|
122
|
+
this.setAccessToken(accessToken);
|
|
124
123
|
originalRequest._isRetry = true;
|
|
125
124
|
originalRequest.headers.Authorization = 'Bearer ' + accessToken;
|
|
126
125
|
return [2 /*return*/, axiosInstance.request(originalRequest)];
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
store.dispatch(auth_1.logout());
|
|
130
|
-
}
|
|
127
|
+
store.dispatch(auth_1.logout());
|
|
131
128
|
_c.label = 2;
|
|
132
129
|
case 2: throw error;
|
|
133
130
|
}
|
|
@@ -141,40 +138,27 @@ var JwtHttpComponent = /** @class */ (function (_super) {
|
|
|
141
138
|
switch (_d.label) {
|
|
142
139
|
case 0:
|
|
143
140
|
if (!!this._axios) return [3 /*break*/, 2];
|
|
144
|
-
// @ts-ignore
|
|
145
141
|
_a = this;
|
|
146
142
|
_c = (_b = axios_1["default"]).create;
|
|
147
143
|
return [4 /*yield*/, this.getAxiosConfig()];
|
|
148
144
|
case 1:
|
|
149
|
-
// @ts-ignore
|
|
150
145
|
_a._axios = _c.apply(_b, [_d.sent()]);
|
|
151
|
-
// @ts-ignore
|
|
152
146
|
this.setRefreshTokenInterceptor(this._axios);
|
|
153
147
|
_d.label = 2;
|
|
154
|
-
case 2:
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
return [2 /*return*/, this._axios];
|
|
148
|
+
case 2: return [2 /*return*/, this._axios];
|
|
157
149
|
}
|
|
158
150
|
});
|
|
159
151
|
});
|
|
160
152
|
};
|
|
161
153
|
JwtHttpComponent.prototype.removeRefreshToken = function () {
|
|
162
154
|
this._refreshToken = null;
|
|
163
|
-
// @ts-ignore
|
|
164
155
|
this.resetConfig();
|
|
165
|
-
|
|
166
|
-
this._components.clientStorage.remove(this.refreshTokenKey,
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
this._components.clientStorage.STORAGE_COOKIE);
|
|
156
|
+
this._components.clientStorage.remove(this.refreshTokenKey, this._components.clientStorage.STORAGE_COOKIE);
|
|
169
157
|
};
|
|
170
158
|
JwtHttpComponent.prototype.setRefreshToken = function (value) {
|
|
171
159
|
this._refreshToken = value;
|
|
172
|
-
// @ts-ignore
|
|
173
160
|
this.resetConfig();
|
|
174
|
-
|
|
175
|
-
this._components.clientStorage.set(this.refreshTokenKey, value,
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
this._components.clientStorage.STORAGE_COOKIE, 180);
|
|
161
|
+
this._components.clientStorage.set(this.refreshTokenKey, value, this._components.clientStorage.STORAGE_COOKIE, 180);
|
|
178
162
|
};
|
|
179
163
|
JwtHttpComponent.prototype.getRefreshToken = function () {
|
|
180
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -183,11 +167,9 @@ var JwtHttpComponent = /** @class */ (function (_super) {
|
|
|
183
167
|
switch (_b.label) {
|
|
184
168
|
case 0:
|
|
185
169
|
if (!(this._refreshToken === false)) return [3 /*break*/, 2];
|
|
186
|
-
// @ts-ignore
|
|
187
170
|
_a = this;
|
|
188
171
|
return [4 /*yield*/, this._components.clientStorage.get(this.refreshTokenKey)];
|
|
189
172
|
case 1:
|
|
190
|
-
// @ts-ignore
|
|
191
173
|
_a._refreshToken = (_b.sent()) || null;
|
|
192
174
|
_b.label = 2;
|
|
193
175
|
case 2: return [2 /*return*/, this._refreshToken];
|
|
@@ -196,10 +178,13 @@ var JwtHttpComponent = /** @class */ (function (_super) {
|
|
|
196
178
|
});
|
|
197
179
|
};
|
|
198
180
|
JwtHttpComponent.prototype.onLogout = function () {
|
|
199
|
-
// @ts-ignore
|
|
200
181
|
this.removeAccessToken();
|
|
201
182
|
this.removeRefreshToken();
|
|
202
183
|
};
|
|
184
|
+
JwtHttpComponent.prototype.onLogin = function (params) {
|
|
185
|
+
this.setAccessToken(params.accessToken);
|
|
186
|
+
this.setRefreshToken(params.refreshToken);
|
|
187
|
+
};
|
|
203
188
|
return JwtHttpComponent;
|
|
204
189
|
}(HttpComponent_1["default"]));
|
|
205
190
|
exports["default"] = JwtHttpComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steroidsjs/core",
|
|
3
|
-
"version": "2.3.0-beta.
|
|
3
|
+
"version": "2.3.0-beta.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Vladimir Kozhin <hello@kozhindev.com>",
|
|
6
6
|
"repository": {
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@babel/preset-env": "^7.13.15",
|
|
63
63
|
"@babel/preset-react": "^7.13.13",
|
|
64
64
|
"@babel/preset-typescript": "^7.13.0",
|
|
65
|
+
"@steroidsjs/eslint-config": "^2.0.1",
|
|
65
66
|
"@types/enzyme": "^3.10.8",
|
|
66
67
|
"@types/enzyme-adapter-react-16": "^1.0.6",
|
|
67
68
|
"@types/jest": "^26.0.22",
|