@propelauth/nextjs 0.0.112-beta.1 → 0.0.114
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/client/index.d.ts +17 -49
- package/dist/client/index.js +79 -139
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +79 -139
- package/dist/client/index.mjs.map +1 -1
- package/dist/server/app-router/index.d.ts +2 -34
- package/dist/server/app-router/index.js +35 -201
- package/dist/server/app-router/index.js.map +1 -1
- package/dist/server/app-router/index.mjs +35 -201
- package/dist/server/app-router/index.mjs.map +1 -1
- package/dist/server/index.d.ts +2 -33
- package/dist/server/index.js +15 -36
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +15 -36
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/pages/index.d.ts +2 -33
- package/dist/server/pages/index.js +25 -53
- package/dist/server/pages/index.js.map +1 -1
- package/dist/server/pages/index.mjs +25 -53
- package/dist/server/pages/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
@@ -2,7 +2,6 @@ import React from 'react';
|
|
2
2
|
|
3
3
|
declare class UserFromToken {
|
4
4
|
userId: string;
|
5
|
-
activeOrgId?: string;
|
6
5
|
orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo;
|
7
6
|
email: string;
|
8
7
|
firstName?: string;
|
@@ -15,15 +14,12 @@ declare class UserFromToken {
|
|
15
14
|
impersonatorUserId?: string;
|
16
15
|
constructor(userId: string, email: string, orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo, firstName?: string, lastName?: string, username?: string, legacyUserId?: string, impersonatorUserId?: string, properties?: {
|
17
16
|
[key: string]: unknown;
|
18
|
-
}
|
19
|
-
getActiveOrg(): OrgMemberInfo | undefined;
|
20
|
-
getActiveOrgId(): string | undefined;
|
17
|
+
});
|
21
18
|
getOrg(orgId: string): OrgMemberInfo | undefined;
|
22
19
|
getOrgByName(orgName: string): OrgMemberInfo | undefined;
|
23
20
|
getOrgs(): OrgMemberInfo[];
|
24
21
|
isImpersonating(): boolean;
|
25
22
|
static fromJSON(json: string): UserFromToken;
|
26
|
-
static fromJwtPayload(payload: InternalUser): UserFromToken;
|
27
23
|
}
|
28
24
|
type OrgIdToOrgMemberInfo = {
|
29
25
|
[orgId: string]: OrgMemberInfo;
|
@@ -50,33 +46,6 @@ declare class OrgMemberInfo {
|
|
50
46
|
get inheritedRolesPlusCurrentRole(): string[];
|
51
47
|
get permissions(): string[];
|
52
48
|
}
|
53
|
-
type InternalOrgMemberInfo = {
|
54
|
-
org_id: string;
|
55
|
-
org_name: string;
|
56
|
-
org_metadata: {
|
57
|
-
[key: string]: any;
|
58
|
-
};
|
59
|
-
url_safe_org_name: string;
|
60
|
-
user_role: string;
|
61
|
-
inherited_user_roles_plus_current_role: string[];
|
62
|
-
user_permissions: string[];
|
63
|
-
};
|
64
|
-
type InternalUser = {
|
65
|
-
user_id: string;
|
66
|
-
org_member_info?: InternalOrgMemberInfo;
|
67
|
-
org_id_to_org_member_info?: {
|
68
|
-
[org_id: string]: InternalOrgMemberInfo;
|
69
|
-
};
|
70
|
-
email: string;
|
71
|
-
first_name?: string;
|
72
|
-
last_name?: string;
|
73
|
-
username?: string;
|
74
|
-
properties?: {
|
75
|
-
[key: string]: unknown;
|
76
|
-
};
|
77
|
-
legacy_user_id?: string;
|
78
|
-
impersonatorUserId?: string;
|
79
|
-
};
|
80
49
|
|
81
50
|
declare class User {
|
82
51
|
userId: string;
|
@@ -88,7 +57,6 @@ declare class User {
|
|
88
57
|
lastName?: string;
|
89
58
|
pictureUrl?: string;
|
90
59
|
orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo;
|
91
|
-
activeOrgId?: string;
|
92
60
|
mfaEnabled: boolean;
|
93
61
|
canCreateOrgs: boolean;
|
94
62
|
updatePasswordRequired: boolean;
|
@@ -99,7 +67,7 @@ declare class User {
|
|
99
67
|
};
|
100
68
|
legacyUserId?: string;
|
101
69
|
impersonatorUserId?: string;
|
102
|
-
constructor({ userId, email, emailConfirmed, hasPassword, username, firstName, lastName, pictureUrl, orgIdToOrgMemberInfo,
|
70
|
+
constructor({ userId, email, emailConfirmed, hasPassword, username, firstName, lastName, pictureUrl, orgIdToOrgMemberInfo, mfaEnabled, canCreateOrgs, updatePasswordRequired, createdAt, lastActiveAt, legacyUserId, properties, impersonatorUserId, }: {
|
103
71
|
userId: string;
|
104
72
|
email: string;
|
105
73
|
emailConfirmed: boolean;
|
@@ -109,7 +77,6 @@ declare class User {
|
|
109
77
|
lastName?: string;
|
110
78
|
pictureUrl?: string;
|
111
79
|
orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo;
|
112
|
-
activeOrgId?: string;
|
113
80
|
mfaEnabled: boolean;
|
114
81
|
canCreateOrgs: boolean;
|
115
82
|
updatePasswordRequired: boolean;
|
@@ -121,8 +88,6 @@ declare class User {
|
|
121
88
|
};
|
122
89
|
impersonatorUserId?: string;
|
123
90
|
});
|
124
|
-
getActiveOrg(): OrgMemberInfo | undefined;
|
125
|
-
getActiveOrgId(): string | undefined;
|
126
91
|
getOrg(orgId: string): OrgMemberInfo | undefined;
|
127
92
|
getOrgByName(orgName: string): OrgMemberInfo | undefined;
|
128
93
|
getOrgs(): OrgMemberInfo[];
|
@@ -133,30 +98,32 @@ type UseUserLoading = {
|
|
133
98
|
isLoggedIn: never;
|
134
99
|
user: never;
|
135
100
|
accessToken: never;
|
136
|
-
setActiveOrg: never;
|
137
101
|
};
|
138
102
|
type UseUserLoggedIn = {
|
139
103
|
loading: false;
|
140
104
|
isLoggedIn: true;
|
141
105
|
user: User;
|
142
106
|
accessToken: string;
|
143
|
-
setActiveOrg: (orgId: string) => Promise<User | undefined>;
|
144
107
|
};
|
145
108
|
type UseUserNotLoggedIn = {
|
146
109
|
loading: false;
|
147
110
|
isLoggedIn: false;
|
148
111
|
user: undefined;
|
149
112
|
accessToken: undefined;
|
150
|
-
setActiveOrg: never;
|
151
113
|
};
|
152
114
|
type UseUser = UseUserLoading | UseUserLoggedIn | UseUserNotLoggedIn;
|
153
115
|
declare function useUser(): UseUser;
|
154
116
|
|
155
117
|
interface RedirectToSignupOptions {
|
156
|
-
postSignupRedirectPath
|
118
|
+
postSignupRedirectPath?: string;
|
119
|
+
userSignupQueryParameters?: Record<string, string>;
|
157
120
|
}
|
158
121
|
interface RedirectToLoginOptions {
|
159
|
-
postLoginRedirectPath
|
122
|
+
postLoginRedirectPath?: string;
|
123
|
+
userSignupQueryParameters?: Record<string, string>;
|
124
|
+
}
|
125
|
+
interface RedirectOptions {
|
126
|
+
redirectBackToUrl?: string;
|
160
127
|
}
|
161
128
|
type AuthProviderProps = {
|
162
129
|
authUrl: string;
|
@@ -168,10 +135,10 @@ declare const AuthProvider: (props: AuthProviderProps) => React.JSX.Element;
|
|
168
135
|
declare function useHostedPageUrls(): {
|
169
136
|
getLoginPageUrl: (opts?: RedirectToLoginOptions | undefined) => string;
|
170
137
|
getSignupPageUrl: (opts?: RedirectToSignupOptions | undefined) => string;
|
171
|
-
getAccountPageUrl: () => string;
|
172
|
-
getOrgPageUrl: (orgId?: string | undefined) => string;
|
173
|
-
getCreateOrgPageUrl: () => string;
|
174
|
-
getSetupSAMLPageUrl: (orgId: string) => string;
|
138
|
+
getAccountPageUrl: (opts?: RedirectOptions | undefined) => string;
|
139
|
+
getOrgPageUrl: (orgId?: string | undefined, opts?: RedirectOptions | undefined) => string;
|
140
|
+
getCreateOrgPageUrl: (opts?: RedirectOptions | undefined) => string;
|
141
|
+
getSetupSAMLPageUrl: (orgId: string, opts?: RedirectOptions | undefined) => string;
|
175
142
|
};
|
176
143
|
|
177
144
|
declare function useLogoutFunction(): () => Promise<void>;
|
@@ -179,9 +146,10 @@ declare function useLogoutFunction(): () => Promise<void>;
|
|
179
146
|
declare function useRedirectFunctions(): {
|
180
147
|
redirectToSignupPage: (opts?: RedirectToSignupOptions | undefined) => void;
|
181
148
|
redirectToLoginPage: (opts?: RedirectToLoginOptions | undefined) => void;
|
182
|
-
redirectToAccountPage: () => void;
|
183
|
-
redirectToOrgPage: (orgId?: string | undefined) => void;
|
184
|
-
redirectToCreateOrgPage: () => void;
|
149
|
+
redirectToAccountPage: (opts?: RedirectOptions | undefined) => void;
|
150
|
+
redirectToOrgPage: (orgId?: string | undefined, opts?: RedirectOptions | undefined) => void;
|
151
|
+
redirectToCreateOrgPage: (opts?: RedirectOptions | undefined) => void;
|
152
|
+
redirectToSetupSAMLPage: (orgId: string, opts?: RedirectOptions | undefined) => void;
|
185
153
|
};
|
186
154
|
interface RedirectProps {
|
187
155
|
children?: React.ReactNode;
|
package/dist/client/index.js
CHANGED
@@ -84,9 +84,8 @@ module.exports = __toCommonJS(client_exports);
|
|
84
84
|
|
85
85
|
// src/user.ts
|
86
86
|
var UserFromToken = class {
|
87
|
-
constructor(userId, email, orgIdToOrgMemberInfo, firstName, lastName, username, legacyUserId, impersonatorUserId, properties
|
87
|
+
constructor(userId, email, orgIdToOrgMemberInfo, firstName, lastName, username, legacyUserId, impersonatorUserId, properties) {
|
88
88
|
this.userId = userId;
|
89
|
-
this.activeOrgId = activeOrgId;
|
90
89
|
this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo;
|
91
90
|
this.email = email;
|
92
91
|
this.firstName = firstName;
|
@@ -96,15 +95,6 @@ var UserFromToken = class {
|
|
96
95
|
this.impersonatorUserId = impersonatorUserId;
|
97
96
|
this.properties = properties;
|
98
97
|
}
|
99
|
-
getActiveOrg() {
|
100
|
-
if (!this.activeOrgId || !this.orgIdToOrgMemberInfo) {
|
101
|
-
return void 0;
|
102
|
-
}
|
103
|
-
return this.orgIdToOrgMemberInfo[this.activeOrgId];
|
104
|
-
}
|
105
|
-
getActiveOrgId() {
|
106
|
-
return this.activeOrgId;
|
107
|
-
}
|
108
98
|
getOrg(orgId) {
|
109
99
|
if (!this.orgIdToOrgMemberInfo) {
|
110
100
|
return void 0;
|
@@ -137,7 +127,9 @@ var UserFromToken = class {
|
|
137
127
|
const obj = JSON.parse(json);
|
138
128
|
const orgIdToOrgMemberInfo = {};
|
139
129
|
for (const orgId in obj.orgIdToOrgMemberInfo) {
|
140
|
-
orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(
|
130
|
+
orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(
|
131
|
+
JSON.stringify(obj.orgIdToOrgMemberInfo[orgId])
|
132
|
+
);
|
141
133
|
}
|
142
134
|
return new UserFromToken(
|
143
135
|
obj.userId,
|
@@ -151,29 +143,6 @@ var UserFromToken = class {
|
|
151
143
|
obj.properties
|
152
144
|
);
|
153
145
|
}
|
154
|
-
static fromJwtPayload(payload) {
|
155
|
-
let activeOrgId;
|
156
|
-
let orgIdToOrgMemberInfo;
|
157
|
-
if (payload.org_member_info) {
|
158
|
-
activeOrgId = payload.org_member_info.org_id;
|
159
|
-
orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo({ [activeOrgId]: payload.org_member_info });
|
160
|
-
} else {
|
161
|
-
activeOrgId = void 0;
|
162
|
-
orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo(payload.org_id_to_org_member_info);
|
163
|
-
}
|
164
|
-
return new UserFromToken(
|
165
|
-
payload.user_id,
|
166
|
-
payload.email,
|
167
|
-
orgIdToOrgMemberInfo,
|
168
|
-
payload.first_name,
|
169
|
-
payload.last_name,
|
170
|
-
payload.username,
|
171
|
-
payload.legacy_user_id,
|
172
|
-
payload.impersonatorUserId,
|
173
|
-
payload.properties,
|
174
|
-
activeOrgId
|
175
|
-
);
|
176
|
-
}
|
177
146
|
};
|
178
147
|
var OrgMemberInfo = class {
|
179
148
|
constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions) {
|
@@ -323,7 +292,6 @@ var User = class {
|
|
323
292
|
lastName,
|
324
293
|
pictureUrl,
|
325
294
|
orgIdToOrgMemberInfo,
|
326
|
-
activeOrgId,
|
327
295
|
mfaEnabled,
|
328
296
|
canCreateOrgs,
|
329
297
|
updatePasswordRequired,
|
@@ -342,7 +310,6 @@ var User = class {
|
|
342
310
|
this.lastName = lastName;
|
343
311
|
this.pictureUrl = pictureUrl;
|
344
312
|
this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo;
|
345
|
-
this.activeOrgId = activeOrgId;
|
346
313
|
this.mfaEnabled = mfaEnabled;
|
347
314
|
this.canCreateOrgs = canCreateOrgs;
|
348
315
|
this.updatePasswordRequired = updatePasswordRequired;
|
@@ -352,15 +319,6 @@ var User = class {
|
|
352
319
|
this.properties = properties;
|
353
320
|
this.impersonatorUserId = impersonatorUserId;
|
354
321
|
}
|
355
|
-
getActiveOrg() {
|
356
|
-
if (!this.activeOrgId) {
|
357
|
-
return void 0;
|
358
|
-
}
|
359
|
-
return this.getOrg(this.activeOrgId);
|
360
|
-
}
|
361
|
-
getActiveOrgId() {
|
362
|
-
return this.activeOrgId;
|
363
|
-
}
|
364
322
|
getOrg(orgId) {
|
365
323
|
var _a;
|
366
324
|
return (_a = this.orgIdToOrgMemberInfo) == null ? void 0 : _a[orgId];
|
@@ -399,24 +357,21 @@ function useUser() {
|
|
399
357
|
loading: true,
|
400
358
|
isLoggedIn: void 0,
|
401
359
|
user: void 0,
|
402
|
-
accessToken: void 0
|
403
|
-
setActiveOrg: void 0
|
360
|
+
accessToken: void 0
|
404
361
|
};
|
405
362
|
} else if (userAndAccessToken.user) {
|
406
363
|
return {
|
407
364
|
loading: false,
|
408
365
|
isLoggedIn: true,
|
409
366
|
user: userAndAccessToken.user,
|
410
|
-
accessToken: userAndAccessToken.accessToken
|
411
|
-
setActiveOrg: context.setActiveOrg
|
367
|
+
accessToken: userAndAccessToken.accessToken
|
412
368
|
};
|
413
369
|
} else {
|
414
370
|
return {
|
415
371
|
loading: false,
|
416
372
|
isLoggedIn: false,
|
417
373
|
user: void 0,
|
418
|
-
accessToken: void 0
|
419
|
-
setActiveOrg: void 0
|
374
|
+
accessToken: void 0
|
420
375
|
};
|
421
376
|
}
|
422
377
|
}
|
@@ -486,7 +441,7 @@ var AuthProvider = (props) => {
|
|
486
441
|
function refreshAuthInfo2() {
|
487
442
|
return __async(this, null, function* () {
|
488
443
|
const action = yield apiGetUserInfo();
|
489
|
-
if (!didCancel) {
|
444
|
+
if (!didCancel && !action.error) {
|
490
445
|
dispatch(action);
|
491
446
|
}
|
492
447
|
});
|
@@ -498,11 +453,23 @@ var AuthProvider = (props) => {
|
|
498
453
|
}, []);
|
499
454
|
(0, import_react2.useEffect)(() => {
|
500
455
|
let didCancel = false;
|
456
|
+
let retryTimer = void 0;
|
457
|
+
function clearAndSetRetryTimer() {
|
458
|
+
if (retryTimer) {
|
459
|
+
clearTimeout(retryTimer);
|
460
|
+
}
|
461
|
+
retryTimer = setTimeout(refreshToken, 30 * 1e3);
|
462
|
+
}
|
501
463
|
function refreshToken() {
|
502
464
|
return __async(this, null, function* () {
|
503
465
|
const action = yield apiGetUserInfo();
|
504
|
-
if (
|
466
|
+
if (didCancel) {
|
467
|
+
return;
|
468
|
+
}
|
469
|
+
if (!action.error) {
|
505
470
|
dispatch(action);
|
471
|
+
} else if (action.error === "unexpected") {
|
472
|
+
clearAndSetRetryTimer();
|
506
473
|
}
|
507
474
|
});
|
508
475
|
}
|
@@ -522,6 +489,9 @@ var AuthProvider = (props) => {
|
|
522
489
|
return () => {
|
523
490
|
didCancel = true;
|
524
491
|
clearInterval(interval);
|
492
|
+
if (retryTimer) {
|
493
|
+
clearTimeout(retryTimer);
|
494
|
+
}
|
525
495
|
if (hasWindow()) {
|
526
496
|
window.removeEventListener("storage", onStorageEvent);
|
527
497
|
window.removeEventListener("online", refreshToken);
|
@@ -551,25 +521,31 @@ var AuthProvider = (props) => {
|
|
551
521
|
}
|
552
522
|
return "/api/auth/signup";
|
553
523
|
};
|
554
|
-
const getAccountPageUrl = (0, import_react2.useCallback)(
|
555
|
-
|
556
|
-
|
524
|
+
const getAccountPageUrl = (0, import_react2.useCallback)(
|
525
|
+
(opts) => {
|
526
|
+
return addReturnToPath(`${props.authUrl}/account`, opts == null ? void 0 : opts.redirectBackToUrl);
|
527
|
+
},
|
528
|
+
[props.authUrl]
|
529
|
+
);
|
557
530
|
const getOrgPageUrl = (0, import_react2.useCallback)(
|
558
|
-
(orgId) => {
|
531
|
+
(orgId, opts) => {
|
559
532
|
if (orgId) {
|
560
|
-
return `${props.authUrl}/org?id=${orgId}
|
533
|
+
return addReturnToPath(`${props.authUrl}/org?id=${orgId}`, opts == null ? void 0 : opts.redirectBackToUrl);
|
561
534
|
} else {
|
562
|
-
return `${props.authUrl}/org
|
535
|
+
return addReturnToPath(`${props.authUrl}/org`, opts == null ? void 0 : opts.redirectBackToUrl);
|
563
536
|
}
|
564
537
|
},
|
565
538
|
[props.authUrl]
|
566
539
|
);
|
567
|
-
const getCreateOrgPageUrl = (0, import_react2.useCallback)(
|
568
|
-
|
569
|
-
|
540
|
+
const getCreateOrgPageUrl = (0, import_react2.useCallback)(
|
541
|
+
(opts) => {
|
542
|
+
return addReturnToPath(`${props.authUrl}/create_org`, opts == null ? void 0 : opts.redirectBackToUrl);
|
543
|
+
},
|
544
|
+
[props.authUrl]
|
545
|
+
);
|
570
546
|
const getSetupSAMLPageUrl = (0, import_react2.useCallback)(
|
571
|
-
(orgId) => {
|
572
|
-
return `${props.authUrl}/saml?id=${orgId}
|
547
|
+
(orgId, opts) => {
|
548
|
+
return addReturnToPath(`${props.authUrl}/saml?id=${orgId}`, opts == null ? void 0 : opts.redirectBackToUrl);
|
573
549
|
},
|
574
550
|
[props.authUrl]
|
575
551
|
);
|
@@ -578,27 +554,19 @@ var AuthProvider = (props) => {
|
|
578
554
|
};
|
579
555
|
const redirectToLoginPage = (opts) => redirectTo(getLoginPageUrl(opts));
|
580
556
|
const redirectToSignupPage = (opts) => redirectTo(getSignupPageUrl(opts));
|
581
|
-
const redirectToAccountPage = () => redirectTo(getAccountPageUrl());
|
582
|
-
const redirectToOrgPage = (orgId) => redirectTo(getOrgPageUrl(orgId));
|
583
|
-
const redirectToCreateOrgPage = () => redirectTo(getCreateOrgPageUrl());
|
584
|
-
const redirectToSetupSAMLPage = (orgId) => redirectTo(getSetupSAMLPageUrl(orgId));
|
585
|
-
const refreshAuthInfo = (
|
557
|
+
const redirectToAccountPage = (opts) => redirectTo(getAccountPageUrl(opts));
|
558
|
+
const redirectToOrgPage = (orgId, opts) => redirectTo(getOrgPageUrl(orgId, opts));
|
559
|
+
const redirectToCreateOrgPage = (opts) => redirectTo(getCreateOrgPageUrl(opts));
|
560
|
+
const redirectToSetupSAMLPage = (orgId, opts) => redirectTo(getSetupSAMLPageUrl(orgId, opts));
|
561
|
+
const refreshAuthInfo = () => __async(void 0, null, function* () {
|
586
562
|
const action = yield apiGetUserInfo();
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
return void 0;
|
595
|
-
} else {
|
596
|
-
dispatch(action);
|
597
|
-
return action.user;
|
598
|
-
}
|
599
|
-
}),
|
600
|
-
[dispatch]
|
601
|
-
);
|
563
|
+
if (action.error) {
|
564
|
+
throw new Error("Failed to refresh token");
|
565
|
+
} else {
|
566
|
+
dispatch(action);
|
567
|
+
return action.user;
|
568
|
+
}
|
569
|
+
});
|
602
570
|
const value = {
|
603
571
|
loading: authState.loading,
|
604
572
|
userAndAccessToken: authState.userAndAccessToken,
|
@@ -615,8 +583,7 @@ var AuthProvider = (props) => {
|
|
615
583
|
getOrgPageUrl,
|
616
584
|
getCreateOrgPageUrl,
|
617
585
|
getSetupSAMLPageUrl,
|
618
|
-
refreshAuthInfo
|
619
|
-
setActiveOrg
|
586
|
+
refreshAuthInfo
|
620
587
|
};
|
621
588
|
return /* @__PURE__ */ import_react2.default.createElement(AuthContext.Provider, { value }, props.children);
|
622
589
|
};
|
@@ -631,7 +598,7 @@ function apiGetUserInfo() {
|
|
631
598
|
credentials: "include"
|
632
599
|
});
|
633
600
|
if (userInfoResponse.ok) {
|
634
|
-
const { userinfo, accessToken, impersonatorUserId
|
601
|
+
const { userinfo, accessToken, impersonatorUserId } = yield userInfoResponse.json();
|
635
602
|
const user = new User({
|
636
603
|
userId: userinfo.user_id,
|
637
604
|
email: userinfo.email,
|
@@ -642,7 +609,6 @@ function apiGetUserInfo() {
|
|
642
609
|
lastName: userinfo.last_name,
|
643
610
|
pictureUrl: userinfo.picture_url,
|
644
611
|
orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),
|
645
|
-
activeOrgId,
|
646
612
|
mfaEnabled: userinfo.mfa_enabled,
|
647
613
|
canCreateOrgs: userinfo.can_create_orgs,
|
648
614
|
updatePasswordRequired: userinfo.update_password_required,
|
@@ -651,63 +617,35 @@ function apiGetUserInfo() {
|
|
651
617
|
properties: userinfo.properties,
|
652
618
|
impersonatorUserId
|
653
619
|
});
|
654
|
-
return { user, accessToken };
|
620
|
+
return { user, accessToken, error: void 0 };
|
655
621
|
} else if (userInfoResponse.status === 401) {
|
656
|
-
return { user: void 0, accessToken: void 0 };
|
622
|
+
return { user: void 0, accessToken: void 0, error: void 0 };
|
657
623
|
} else {
|
658
624
|
console.info("Failed to refresh token", userInfoResponse);
|
625
|
+
return { error: "unexpected" };
|
659
626
|
}
|
660
627
|
} catch (e) {
|
661
628
|
console.info("Failed to refresh token", e);
|
629
|
+
return { error: "unexpected" };
|
662
630
|
}
|
663
|
-
throw new Error("Failed to refresh token");
|
664
|
-
});
|
665
|
-
}
|
666
|
-
function apiPostSetActiveOrg(orgId) {
|
667
|
-
return __async(this, null, function* () {
|
668
|
-
try {
|
669
|
-
const queryParams = new URLSearchParams({ active_org_id: orgId }).toString();
|
670
|
-
const url = `/api/auth/set-active-org?${queryParams}`;
|
671
|
-
const userInfoResponse = yield fetch(url, {
|
672
|
-
method: "POST",
|
673
|
-
headers: {
|
674
|
-
"Content-Type": "application/json"
|
675
|
-
},
|
676
|
-
credentials: "include"
|
677
|
-
});
|
678
|
-
if (userInfoResponse.ok) {
|
679
|
-
const { userinfo, accessToken, impersonatorUserId, activeOrgId } = yield userInfoResponse.json();
|
680
|
-
const user = new User({
|
681
|
-
userId: userinfo.user_id,
|
682
|
-
email: userinfo.email,
|
683
|
-
emailConfirmed: userinfo.email_confirmed,
|
684
|
-
hasPassword: userinfo.has_password,
|
685
|
-
username: userinfo.username,
|
686
|
-
firstName: userinfo.first_name,
|
687
|
-
lastName: userinfo.last_name,
|
688
|
-
pictureUrl: userinfo.picture_url,
|
689
|
-
orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),
|
690
|
-
activeOrgId,
|
691
|
-
mfaEnabled: userinfo.mfa_enabled,
|
692
|
-
canCreateOrgs: userinfo.can_create_orgs,
|
693
|
-
updatePasswordRequired: userinfo.update_password_required,
|
694
|
-
createdAt: userinfo.created_at,
|
695
|
-
lastActiveAt: userinfo.last_active_at,
|
696
|
-
properties: userinfo.properties,
|
697
|
-
impersonatorUserId
|
698
|
-
});
|
699
|
-
return { user, accessToken, error: void 0 };
|
700
|
-
} else if (userInfoResponse.status === 401) {
|
701
|
-
return { error: "not_in_org" };
|
702
|
-
} else {
|
703
|
-
console.info("Failed to set active org", userInfoResponse);
|
704
|
-
}
|
705
|
-
} catch (e) {
|
706
|
-
console.info("Failed to set active org", e);
|
707
|
-
}
|
708
|
-
throw new Error("Failed to set active org");
|
709
631
|
});
|
710
632
|
}
|
633
|
+
var encodeBase64 = (str) => {
|
634
|
+
const encode = window ? window.btoa : btoa;
|
635
|
+
return encode(str);
|
636
|
+
};
|
637
|
+
var addReturnToPath = (url, returnToPath) => {
|
638
|
+
if (!returnToPath) {
|
639
|
+
return url;
|
640
|
+
}
|
641
|
+
let qs = new URLSearchParams();
|
642
|
+
qs.set("rt", encodeBase64(returnToPath));
|
643
|
+
if (url.includes("?")) {
|
644
|
+
return `${url}&${qs.toString()}`;
|
645
|
+
} else {
|
646
|
+
return `${url}?${qs.toString()}`;
|
647
|
+
}
|
648
|
+
};
|
711
649
|
|
712
650
|
// src/client/useHostedPageUrls.tsx
|
713
651
|
var import_react3 = require("react");
|
@@ -757,14 +695,16 @@ function useRedirectFunctions() {
|
|
757
695
|
redirectToSignupPage,
|
758
696
|
redirectToLoginPage,
|
759
697
|
redirectToOrgPage,
|
760
|
-
redirectToCreateOrgPage
|
698
|
+
redirectToCreateOrgPage,
|
699
|
+
redirectToSetupSAMLPage
|
761
700
|
} = context;
|
762
701
|
return {
|
763
702
|
redirectToSignupPage,
|
764
703
|
redirectToLoginPage,
|
765
704
|
redirectToAccountPage,
|
766
705
|
redirectToOrgPage,
|
767
|
-
redirectToCreateOrgPage
|
706
|
+
redirectToCreateOrgPage,
|
707
|
+
redirectToSetupSAMLPage
|
768
708
|
};
|
769
709
|
}
|
770
710
|
function RedirectToSignup({ children }) {
|