@placeos/ts-client 4.7.9 → 4.7.10
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/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +940 -930
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/auth/functions.ts +28 -5
package/package.json
CHANGED
package/src/auth/functions.ts
CHANGED
|
@@ -90,6 +90,25 @@ const _online_observer = _online.asObservable();
|
|
|
90
90
|
|
|
91
91
|
let _failed_count = 0;
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @private
|
|
95
|
+
* Resolve a URL against the authority's domain if it is a relative path.
|
|
96
|
+
* If the URL is already absolute (starts with http:// or https://), return as-is.
|
|
97
|
+
* If the URL is relative (starts with /), prepend the protocol and authority domain.
|
|
98
|
+
*/
|
|
99
|
+
function resolveAuthorityUrl(url: string): string {
|
|
100
|
+
if (!url || url.startsWith('http://') || url.startsWith('https://')) {
|
|
101
|
+
return url;
|
|
102
|
+
}
|
|
103
|
+
const domain = _authority?.domain;
|
|
104
|
+
if (domain) {
|
|
105
|
+
const secure =
|
|
106
|
+
_options.secure || window.location?.protocol.indexOf('https') >= 0;
|
|
107
|
+
return `${secure ? 'https:' : 'http:'}//${domain}${url}`;
|
|
108
|
+
}
|
|
109
|
+
return url;
|
|
110
|
+
}
|
|
111
|
+
|
|
93
112
|
/** API Endpoint for the retrieved version of PlaceOS */
|
|
94
113
|
export function apiEndpoint(): string {
|
|
95
114
|
const secure =
|
|
@@ -398,7 +417,9 @@ export function authorise(
|
|
|
398
417
|
* Logout and clear user credentials for the application
|
|
399
418
|
*/
|
|
400
419
|
export function logout(): void {
|
|
401
|
-
const url =
|
|
420
|
+
const url = resolveAuthorityUrl(
|
|
421
|
+
_authority ? _authority.logout_url : '/logout',
|
|
422
|
+
);
|
|
402
423
|
fetch(url, {
|
|
403
424
|
method: 'GET',
|
|
404
425
|
redirect: 'manual',
|
|
@@ -582,10 +603,12 @@ export function sendToLogin(api_authority: PlaceAuthority): void {
|
|
|
582
603
|
/* istanbul ignore else */
|
|
583
604
|
if (_options.handle_login !== false && !_redirecting) {
|
|
584
605
|
log('Auth', 'Redirecting to login page...');
|
|
585
|
-
// Redirect to login form
|
|
586
|
-
const url =
|
|
587
|
-
|
|
588
|
-
|
|
606
|
+
// Redirect to login form, resolving relative URLs against the authority domain
|
|
607
|
+
const url = resolveAuthorityUrl(
|
|
608
|
+
api_authority!.login_url?.replace(
|
|
609
|
+
'{{url}}',
|
|
610
|
+
encodeURIComponent(window.location?.href),
|
|
611
|
+
),
|
|
589
612
|
);
|
|
590
613
|
setTimeout(() => window.location?.assign(url), 300);
|
|
591
614
|
_redirecting = true;
|