@atls/react-identity-links 0.0.1 → 0.0.2
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/dist/identity-link.component.js +1 -1
- package/dist/identity-link.component.test.js +5 -5
- package/dist/use-browser-effect.hook.js +11 -0
- package/dist/use-identity-url.hook.js +23 -30
- package/package.json +11 -8
- package/dist/identity-link.component.d.ts +0 -3
- package/dist/identity-link.component.test.d.ts +0 -1
- package/dist/identity-url.interfaces.d.ts +0 -7
- package/dist/index.d.ts +0 -3
- package/dist/use-identity-url.hook.d.ts +0 -10
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IdentityLink = void 0;
|
|
4
4
|
const use_identity_url_hook_1 = require("./use-identity-url.hook");
|
|
5
5
|
const IdentityLink = ({ children, type, returnTo, subdomain, substractHost, }) => {
|
|
6
|
-
const url = use_identity_url_hook_1.useIdentityUrl({ type, returnTo, subdomain, substractHost });
|
|
6
|
+
const url = (0, use_identity_url_hook_1.useIdentityUrl)({ type, returnTo, subdomain, substractHost });
|
|
7
7
|
if (!children || !url) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_2 = require("@testing-library/react");
|
|
8
6
|
require("@testing-library/jest-dom/extend-expect");
|
|
7
|
+
const react_1 = require("@testing-library/react");
|
|
8
|
+
const react_2 = __importDefault(require("react"));
|
|
9
9
|
const identity_link_component_1 = require("./identity-link.component");
|
|
10
10
|
describe('identity-link.component', () => {
|
|
11
11
|
const originalLocation = window.location;
|
|
@@ -17,8 +17,8 @@ describe('identity-link.component', () => {
|
|
|
17
17
|
mockWindowLocation(originalLocation);
|
|
18
18
|
});
|
|
19
19
|
it('without params', async () => {
|
|
20
|
-
mockWindowLocation(new URL('https://identity.
|
|
21
|
-
const { getByText } =
|
|
22
|
-
expect(getByText('Login')).toHaveAttribute('href', 'https://accounts.
|
|
20
|
+
mockWindowLocation(new URL('https://identity.monstrs.dev'));
|
|
21
|
+
const { getByText } = (0, react_1.render)(react_2.default.createElement(identity_link_component_1.IdentityLink, null, (url) => react_2.default.createElement("a", { href: url }, "Login")));
|
|
22
|
+
expect(getByText('Login')).toHaveAttribute('href', 'https://accounts.monstrs.dev/auth/login?return_to=https://identity.monstrs.dev/');
|
|
23
23
|
});
|
|
24
24
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBrowserEffect = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useBrowserEffect = (effect, deps) => {
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return (0, react_1.useEffect)(effect, deps);
|
|
10
|
+
};
|
|
11
|
+
exports.useBrowserEffect = useBrowserEffect;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useIdentityUrl = exports.
|
|
3
|
+
exports.useIdentityUrl = exports.identityUrlTypes = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const tldjs_1 = require("tldjs");
|
|
6
|
+
const use_browser_effect_hook_1 = require("./use-browser-effect.hook");
|
|
7
|
+
exports.identityUrlTypes = {
|
|
7
8
|
login: '/auth/login',
|
|
8
9
|
registration: '/auth/registration',
|
|
9
10
|
verification: '/auth/verification',
|
|
@@ -11,36 +12,28 @@ exports.IdentityUrlTypes = {
|
|
|
11
12
|
logout: '/auth/logout',
|
|
12
13
|
settings: '/profile/settings',
|
|
13
14
|
};
|
|
14
|
-
const useIdentityUrl = ({ type = 'login',
|
|
15
|
-
const [url, setUrl] =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let returnToValue = href;
|
|
32
|
-
if (returnTo) {
|
|
33
|
-
if (returnTo.startsWith('http')) {
|
|
34
|
-
returnToValue = returnTo;
|
|
35
|
-
}
|
|
36
|
-
else if (returnTo.startsWith('/')) {
|
|
37
|
-
returnToValue = `${origin}${returnTo}`;
|
|
38
|
-
}
|
|
15
|
+
const useIdentityUrl = ({ type = 'login', returnTo } = {}) => {
|
|
16
|
+
const [url, setUrl] = (0, react_1.useState)(null);
|
|
17
|
+
(0, use_browser_effect_hook_1.useBrowserEffect)(() => {
|
|
18
|
+
const { hostname, origin, href, protocol } = window.location;
|
|
19
|
+
const path = exports.identityUrlTypes[type];
|
|
20
|
+
const domain = hostname === 'localhost' ? 'localhost:4433' : (0, tldjs_1.getDomain)(hostname);
|
|
21
|
+
if (returnTo === false) {
|
|
22
|
+
setUrl(`${protocol}//accounts.${domain}${path}`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
let returnToValue = href;
|
|
26
|
+
if (returnTo) {
|
|
27
|
+
if (returnTo.startsWith('http')) {
|
|
28
|
+
returnToValue = returnTo;
|
|
29
|
+
}
|
|
30
|
+
else if (returnTo.startsWith('/')) {
|
|
31
|
+
returnToValue = `${origin}${returnTo}`;
|
|
39
32
|
}
|
|
40
|
-
setUrl(`https://${host}${path}?return_to=${returnToValue}`);
|
|
41
33
|
}
|
|
34
|
+
setUrl(`${protocol}//accounts.${domain}${path}?return_to=${returnToValue}`);
|
|
42
35
|
}
|
|
43
|
-
}, [type,
|
|
36
|
+
}, [type, returnTo]);
|
|
44
37
|
return url;
|
|
45
38
|
};
|
|
46
39
|
exports.useIdentityUrl = useIdentityUrl;
|
package/package.json
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atls/react-identity-links",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "yarn
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"build": "yarn library build",
|
|
11
|
+
"prepack": "yarn run build",
|
|
12
|
+
"postpack": "rm -rf dist"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tldjs": "^2.3.1"
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
|
-
"@testing-library/jest-dom": "^5.
|
|
16
|
-
"@testing-library/react": "^12.1.
|
|
18
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
19
|
+
"@testing-library/react": "^12.1.3",
|
|
17
20
|
"@testing-library/react-hooks": "^7.0.2",
|
|
18
|
-
"@types/react": "^17.0.
|
|
19
|
-
"@types/react-dom": "^17.0.
|
|
21
|
+
"@types/react": "^17.0.39",
|
|
22
|
+
"@types/react-dom": "^17.0.11",
|
|
20
23
|
"@types/testing-library__jest-dom": "^5.14.1",
|
|
21
24
|
"react": "^17.0.2",
|
|
22
25
|
"react-dom": "^17.0.2"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom/extend-expect';
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UseIdentityUrlProps } from './identity-url.interfaces';
|
|
2
|
-
export declare const IdentityUrlTypes: {
|
|
3
|
-
login: string;
|
|
4
|
-
registration: string;
|
|
5
|
-
verification: string;
|
|
6
|
-
recovery: string;
|
|
7
|
-
logout: string;
|
|
8
|
-
settings: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const useIdentityUrl: ({ type, subdomain, returnTo, substractHost, }?: UseIdentityUrlProps) => string | null;
|