@propelauth/nextjs 0.0.111 → 0.0.112-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/client/index.d.ts +40 -2
- package/dist/client/index.js +122 -15
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +122 -15
- package/dist/client/index.mjs.map +1 -1
- package/dist/server/app-router/index.d.ts +34 -2
- package/dist/server/app-router/index.js +201 -35
- package/dist/server/app-router/index.js.map +1 -1
- package/dist/server/app-router/index.mjs +201 -35
- package/dist/server/app-router/index.mjs.map +1 -1
- package/dist/server/index.d.ts +32 -1
- package/dist/server/index.js +36 -15
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +36 -15
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/pages/index.d.ts +32 -1
- package/dist/server/pages/index.js +51 -23
- package/dist/server/pages/index.js.map +1 -1
- package/dist/server/pages/index.mjs +51 -23
- package/dist/server/pages/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/client/index.mjs
CHANGED
@@ -41,8 +41,9 @@ var __async = (__this, __arguments, generator) => {
|
|
41
41
|
|
42
42
|
// src/user.ts
|
43
43
|
var UserFromToken = class {
|
44
|
-
constructor(userId, email, orgIdToOrgMemberInfo, firstName, lastName, username, legacyUserId, impersonatorUserId, properties) {
|
44
|
+
constructor(userId, email, orgIdToOrgMemberInfo, firstName, lastName, username, legacyUserId, impersonatorUserId, properties, activeOrgId) {
|
45
45
|
this.userId = userId;
|
46
|
+
this.activeOrgId = activeOrgId;
|
46
47
|
this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo;
|
47
48
|
this.email = email;
|
48
49
|
this.firstName = firstName;
|
@@ -52,6 +53,15 @@ var UserFromToken = class {
|
|
52
53
|
this.impersonatorUserId = impersonatorUserId;
|
53
54
|
this.properties = properties;
|
54
55
|
}
|
56
|
+
getActiveOrg() {
|
57
|
+
if (!this.activeOrgId || !this.orgIdToOrgMemberInfo) {
|
58
|
+
return void 0;
|
59
|
+
}
|
60
|
+
return this.orgIdToOrgMemberInfo[this.activeOrgId];
|
61
|
+
}
|
62
|
+
getActiveOrgId() {
|
63
|
+
return this.activeOrgId;
|
64
|
+
}
|
55
65
|
getOrg(orgId) {
|
56
66
|
if (!this.orgIdToOrgMemberInfo) {
|
57
67
|
return void 0;
|
@@ -84,9 +94,7 @@ var UserFromToken = class {
|
|
84
94
|
const obj = JSON.parse(json);
|
85
95
|
const orgIdToOrgMemberInfo = {};
|
86
96
|
for (const orgId in obj.orgIdToOrgMemberInfo) {
|
87
|
-
orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(
|
88
|
-
JSON.stringify(obj.orgIdToOrgMemberInfo[orgId])
|
89
|
-
);
|
97
|
+
orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(JSON.stringify(obj.orgIdToOrgMemberInfo[orgId]));
|
90
98
|
}
|
91
99
|
return new UserFromToken(
|
92
100
|
obj.userId,
|
@@ -100,6 +108,29 @@ var UserFromToken = class {
|
|
100
108
|
obj.properties
|
101
109
|
);
|
102
110
|
}
|
111
|
+
static fromJwtPayload(payload) {
|
112
|
+
let activeOrgId;
|
113
|
+
let orgIdToOrgMemberInfo;
|
114
|
+
if (payload.org_member_info) {
|
115
|
+
activeOrgId = payload.org_member_info.org_id;
|
116
|
+
orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo({ [activeOrgId]: payload.org_member_info });
|
117
|
+
} else {
|
118
|
+
activeOrgId = void 0;
|
119
|
+
orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo(payload.org_id_to_org_member_info);
|
120
|
+
}
|
121
|
+
return new UserFromToken(
|
122
|
+
payload.user_id,
|
123
|
+
payload.email,
|
124
|
+
orgIdToOrgMemberInfo,
|
125
|
+
payload.first_name,
|
126
|
+
payload.last_name,
|
127
|
+
payload.username,
|
128
|
+
payload.legacy_user_id,
|
129
|
+
payload.impersonatorUserId,
|
130
|
+
payload.properties,
|
131
|
+
activeOrgId
|
132
|
+
);
|
133
|
+
}
|
103
134
|
};
|
104
135
|
var OrgMemberInfo = class {
|
105
136
|
constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions) {
|
@@ -249,6 +280,7 @@ var User = class {
|
|
249
280
|
lastName,
|
250
281
|
pictureUrl,
|
251
282
|
orgIdToOrgMemberInfo,
|
283
|
+
activeOrgId,
|
252
284
|
mfaEnabled,
|
253
285
|
canCreateOrgs,
|
254
286
|
updatePasswordRequired,
|
@@ -267,6 +299,7 @@ var User = class {
|
|
267
299
|
this.lastName = lastName;
|
268
300
|
this.pictureUrl = pictureUrl;
|
269
301
|
this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo;
|
302
|
+
this.activeOrgId = activeOrgId;
|
270
303
|
this.mfaEnabled = mfaEnabled;
|
271
304
|
this.canCreateOrgs = canCreateOrgs;
|
272
305
|
this.updatePasswordRequired = updatePasswordRequired;
|
@@ -276,6 +309,15 @@ var User = class {
|
|
276
309
|
this.properties = properties;
|
277
310
|
this.impersonatorUserId = impersonatorUserId;
|
278
311
|
}
|
312
|
+
getActiveOrg() {
|
313
|
+
if (!this.activeOrgId) {
|
314
|
+
return void 0;
|
315
|
+
}
|
316
|
+
return this.getOrg(this.activeOrgId);
|
317
|
+
}
|
318
|
+
getActiveOrgId() {
|
319
|
+
return this.activeOrgId;
|
320
|
+
}
|
279
321
|
getOrg(orgId) {
|
280
322
|
var _a;
|
281
323
|
return (_a = this.orgIdToOrgMemberInfo) == null ? void 0 : _a[orgId];
|
@@ -314,21 +356,24 @@ function useUser() {
|
|
314
356
|
loading: true,
|
315
357
|
isLoggedIn: void 0,
|
316
358
|
user: void 0,
|
317
|
-
accessToken: void 0
|
359
|
+
accessToken: void 0,
|
360
|
+
setActiveOrg: void 0
|
318
361
|
};
|
319
362
|
} else if (userAndAccessToken.user) {
|
320
363
|
return {
|
321
364
|
loading: false,
|
322
365
|
isLoggedIn: true,
|
323
366
|
user: userAndAccessToken.user,
|
324
|
-
accessToken: userAndAccessToken.accessToken
|
367
|
+
accessToken: userAndAccessToken.accessToken,
|
368
|
+
setActiveOrg: context.setActiveOrg
|
325
369
|
};
|
326
370
|
} else {
|
327
371
|
return {
|
328
372
|
loading: false,
|
329
373
|
isLoggedIn: false,
|
330
374
|
user: void 0,
|
331
|
-
accessToken: void 0
|
375
|
+
accessToken: void 0,
|
376
|
+
setActiveOrg: void 0
|
332
377
|
};
|
333
378
|
}
|
334
379
|
}
|
@@ -381,10 +426,13 @@ var AuthProvider = (props) => {
|
|
381
426
|
const [authState, dispatchInner] = useReducer(authStateReducer, initialAuthState);
|
382
427
|
const router = useRouter();
|
383
428
|
const reloadOnAuthChange = (_a = props.reloadOnAuthChange) != null ? _a : true;
|
384
|
-
const dispatch = useCallback(
|
385
|
-
|
386
|
-
|
387
|
-
|
429
|
+
const dispatch = useCallback(
|
430
|
+
(action) => {
|
431
|
+
dispatchInner(action);
|
432
|
+
saveUserToLocalStorage(action.user);
|
433
|
+
},
|
434
|
+
[dispatchInner]
|
435
|
+
);
|
388
436
|
useEffect(() => {
|
389
437
|
if (reloadOnAuthChange && authState.authChangeDetected) {
|
390
438
|
router.refresh();
|
@@ -491,11 +539,23 @@ var AuthProvider = (props) => {
|
|
491
539
|
const redirectToOrgPage = (orgId) => redirectTo(getOrgPageUrl(orgId));
|
492
540
|
const redirectToCreateOrgPage = () => redirectTo(getCreateOrgPageUrl());
|
493
541
|
const redirectToSetupSAMLPage = (orgId) => redirectTo(getSetupSAMLPageUrl(orgId));
|
494
|
-
const refreshAuthInfo = () => __async(void 0, null, function* () {
|
542
|
+
const refreshAuthInfo = useCallback(() => __async(void 0, null, function* () {
|
495
543
|
const action = yield apiGetUserInfo();
|
496
544
|
dispatch(action);
|
497
545
|
return action.user;
|
498
|
-
});
|
546
|
+
}), [dispatch]);
|
547
|
+
const setActiveOrg = useCallback(
|
548
|
+
(orgId) => __async(void 0, null, function* () {
|
549
|
+
const action = yield apiPostSetActiveOrg(orgId);
|
550
|
+
if (action.error === "not_in_org") {
|
551
|
+
return void 0;
|
552
|
+
} else {
|
553
|
+
dispatch(action);
|
554
|
+
return action.user;
|
555
|
+
}
|
556
|
+
}),
|
557
|
+
[dispatch]
|
558
|
+
);
|
499
559
|
const value = {
|
500
560
|
loading: authState.loading,
|
501
561
|
userAndAccessToken: authState.userAndAccessToken,
|
@@ -512,7 +572,8 @@ var AuthProvider = (props) => {
|
|
512
572
|
getOrgPageUrl,
|
513
573
|
getCreateOrgPageUrl,
|
514
574
|
getSetupSAMLPageUrl,
|
515
|
-
refreshAuthInfo
|
575
|
+
refreshAuthInfo,
|
576
|
+
setActiveOrg
|
516
577
|
};
|
517
578
|
return /* @__PURE__ */ React.createElement(AuthContext.Provider, { value }, props.children);
|
518
579
|
};
|
@@ -527,7 +588,7 @@ function apiGetUserInfo() {
|
|
527
588
|
credentials: "include"
|
528
589
|
});
|
529
590
|
if (userInfoResponse.ok) {
|
530
|
-
const { userinfo, accessToken, impersonatorUserId } = yield userInfoResponse.json();
|
591
|
+
const { userinfo, accessToken, impersonatorUserId, activeOrgId } = yield userInfoResponse.json();
|
531
592
|
const user = new User({
|
532
593
|
userId: userinfo.user_id,
|
533
594
|
email: userinfo.email,
|
@@ -538,6 +599,7 @@ function apiGetUserInfo() {
|
|
538
599
|
lastName: userinfo.last_name,
|
539
600
|
pictureUrl: userinfo.picture_url,
|
540
601
|
orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),
|
602
|
+
activeOrgId,
|
541
603
|
mfaEnabled: userinfo.mfa_enabled,
|
542
604
|
canCreateOrgs: userinfo.can_create_orgs,
|
543
605
|
updatePasswordRequired: userinfo.update_password_required,
|
@@ -558,6 +620,51 @@ function apiGetUserInfo() {
|
|
558
620
|
throw new Error("Failed to refresh token");
|
559
621
|
});
|
560
622
|
}
|
623
|
+
function apiPostSetActiveOrg(orgId) {
|
624
|
+
return __async(this, null, function* () {
|
625
|
+
try {
|
626
|
+
const queryParams = new URLSearchParams({ active_org_id: orgId }).toString();
|
627
|
+
const url = `/api/auth/set-active-org?${queryParams}`;
|
628
|
+
const userInfoResponse = yield fetch(url, {
|
629
|
+
method: "POST",
|
630
|
+
headers: {
|
631
|
+
"Content-Type": "application/json"
|
632
|
+
},
|
633
|
+
credentials: "include"
|
634
|
+
});
|
635
|
+
if (userInfoResponse.ok) {
|
636
|
+
const { userinfo, accessToken, impersonatorUserId, activeOrgId } = yield userInfoResponse.json();
|
637
|
+
const user = new User({
|
638
|
+
userId: userinfo.user_id,
|
639
|
+
email: userinfo.email,
|
640
|
+
emailConfirmed: userinfo.email_confirmed,
|
641
|
+
hasPassword: userinfo.has_password,
|
642
|
+
username: userinfo.username,
|
643
|
+
firstName: userinfo.first_name,
|
644
|
+
lastName: userinfo.last_name,
|
645
|
+
pictureUrl: userinfo.picture_url,
|
646
|
+
orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),
|
647
|
+
activeOrgId,
|
648
|
+
mfaEnabled: userinfo.mfa_enabled,
|
649
|
+
canCreateOrgs: userinfo.can_create_orgs,
|
650
|
+
updatePasswordRequired: userinfo.update_password_required,
|
651
|
+
createdAt: userinfo.created_at,
|
652
|
+
lastActiveAt: userinfo.last_active_at,
|
653
|
+
properties: userinfo.properties,
|
654
|
+
impersonatorUserId
|
655
|
+
});
|
656
|
+
return { user, accessToken, error: void 0 };
|
657
|
+
} else if (userInfoResponse.status === 401) {
|
658
|
+
return { error: "not_in_org" };
|
659
|
+
} else {
|
660
|
+
console.info("Failed to set active org", userInfoResponse);
|
661
|
+
}
|
662
|
+
} catch (e) {
|
663
|
+
console.info("Failed to set active org", e);
|
664
|
+
}
|
665
|
+
throw new Error("Failed to set active org");
|
666
|
+
});
|
667
|
+
}
|
561
668
|
|
562
669
|
// src/client/useHostedPageUrls.tsx
|
563
670
|
import { useContext as useContext2 } from "react";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/user.ts","../../src/client/AuthProvider.tsx","../../src/client/utils.ts","../../src/client/useUser.tsx","../../src/client/useHostedPageUrls.tsx","../../src/client/useLogoutFunction.ts","../../src/client/useRedirectFunctions.tsx","../../src/client/useRefreshAuth.ts"],"sourcesContent":["export class UserFromToken {\n public userId: string\n public orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n\n // Metadata about the user\n public email: string\n public firstName?: string\n public lastName?: string\n public username?: string\n public properties?: { [key: string]: unknown }\n\n // If you used our migration APIs to migrate this user from a different system,\n // this is their original ID from that system.\n public legacyUserId?: string\n public impersonatorUserId?: string\n\n constructor(\n userId: string,\n email: string,\n orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo,\n firstName?: string,\n lastName?: string,\n username?: string,\n legacyUserId?: string,\n impersonatorUserId?: string,\n properties?: { [key: string]: unknown },\n ) {\n this.userId = userId\n this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo\n\n this.email = email\n this.firstName = firstName\n this.lastName = lastName\n this.username = username\n\n this.legacyUserId = legacyUserId\n this.impersonatorUserId = impersonatorUserId\n\n this.properties = properties\n }\n\n public getOrg(orgId: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n return this.orgIdToOrgMemberInfo[orgId]\n }\n\n public getOrgByName(orgName: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n const urlSafeOrgName = orgName.toLowerCase().replace(/ /g, \"-\")\n for (const orgId in this.orgIdToOrgMemberInfo) {\n const orgMemberInfo = this.orgIdToOrgMemberInfo[orgId]\n if (orgMemberInfo.urlSafeOrgName === urlSafeOrgName) {\n return orgMemberInfo\n }\n }\n\n return undefined\n }\n\n public getOrgs(): OrgMemberInfo[] {\n if (!this.orgIdToOrgMemberInfo) {\n return []\n }\n\n return Object.values(this.orgIdToOrgMemberInfo)\n }\n\n public isImpersonating(): boolean {\n return !!this.impersonatorUserId\n }\n\n public static fromJSON(json: string): UserFromToken {\n const obj = JSON.parse(json)\n const orgIdToOrgMemberInfo: OrgIdToOrgMemberInfo = {}\n for (const orgId in obj.orgIdToOrgMemberInfo) {\n orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(\n JSON.stringify(obj.orgIdToOrgMemberInfo[orgId])\n )\n }\n return new UserFromToken(\n obj.userId,\n obj.email,\n orgIdToOrgMemberInfo,\n obj.firstName,\n obj.lastName,\n obj.username,\n obj.legacyUserId,\n obj.impersonatorUserId,\n obj.properties,\n )\n }\n}\n\nexport type OrgIdToOrgMemberInfo = {\n [orgId: string]: OrgMemberInfo\n}\n\nexport class OrgMemberInfo {\n public orgId: string\n public orgName: string\n public orgMetadata: { [key: string]: any }\n public urlSafeOrgName: string\n\n public userAssignedRole: string\n public userInheritedRolesPlusCurrentRole: string[]\n public userPermissions: string[]\n\n constructor(\n orgId: string,\n orgName: string,\n orgMetadata: { [key: string]: any },\n urlSafeOrgName: string,\n userAssignedRole: string,\n userInheritedRolesPlusCurrentRole: string[],\n userPermissions: string[]\n ) {\n this.orgId = orgId\n this.orgName = orgName\n this.orgMetadata = orgMetadata\n this.urlSafeOrgName = urlSafeOrgName\n\n this.userAssignedRole = userAssignedRole\n this.userInheritedRolesPlusCurrentRole = userInheritedRolesPlusCurrentRole\n this.userPermissions = userPermissions\n }\n\n // validation methods\n\n public isRole(role: string): boolean {\n return this.userAssignedRole === role\n }\n\n public isAtLeastRole(role: string): boolean {\n return this.userInheritedRolesPlusCurrentRole.includes(role)\n }\n\n public hasPermission(permission: string): boolean {\n return this.userPermissions.includes(permission)\n }\n\n public hasAllPermissions(permissions: string[]): boolean {\n return permissions.every((permission) => this.hasPermission(permission))\n }\n\n public static fromJSON(json: string): OrgMemberInfo {\n const obj = JSON.parse(json)\n return new OrgMemberInfo(\n obj.orgId,\n obj.orgName,\n obj.orgMetadata,\n obj.urlSafeOrgName,\n obj.userAssignedRole,\n obj.userInheritedRolesPlusCurrentRole,\n obj.userPermissions\n )\n }\n\n // getters for the private fields\n\n get assignedRole(): string {\n return this.userAssignedRole\n }\n\n get inheritedRolesPlusCurrentRole(): string[] {\n return this.userInheritedRolesPlusCurrentRole\n }\n\n get permissions(): string[] {\n return this.userPermissions\n }\n}\n\n// These Internal types exist since the server returns snake case, but typescript/javascript\n// convention is camelCase.\nexport type InternalOrgMemberInfo = {\n org_id: string\n org_name: string\n org_metadata: { [key: string]: any }\n url_safe_org_name: string\n user_role: string\n inherited_user_roles_plus_current_role: string[]\n user_permissions: string[]\n}\nexport type InternalUser = {\n user_id: string\n org_id_to_org_member_info?: { [org_id: string]: InternalOrgMemberInfo }\n\n email: string\n first_name?: string\n last_name?: string\n username?: string\n properties?: { [key: string]: unknown }\n\n // If you used our migration APIs to migrate this user from a different system, this is their original ID from that system.\n legacy_user_id?: string\n impersonatorUserId?: string\n}\n\nexport function toUser(snake_case: InternalUser): UserFromToken {\n return new UserFromToken(\n snake_case.user_id,\n snake_case.email,\n toOrgIdToOrgMemberInfo(snake_case.org_id_to_org_member_info),\n snake_case.first_name,\n snake_case.last_name,\n snake_case.username,\n snake_case.legacy_user_id,\n snake_case.impersonatorUserId,\n snake_case.properties,\n )\n}\n\nexport function toOrgIdToOrgMemberInfo(snake_case?: {\n [org_id: string]: InternalOrgMemberInfo\n}): OrgIdToOrgMemberInfo | undefined {\n if (snake_case === undefined) {\n return undefined\n }\n const camelCase: OrgIdToOrgMemberInfo = {}\n\n for (const key of Object.keys(snake_case)) {\n const snakeCaseValue = snake_case[key]\n if (snakeCaseValue) {\n camelCase[key] = new OrgMemberInfo(\n snakeCaseValue.org_id,\n snakeCaseValue.org_name,\n snakeCaseValue.org_metadata,\n snakeCaseValue.url_safe_org_name,\n snakeCaseValue.user_role,\n snakeCaseValue.inherited_user_roles_plus_current_role,\n snakeCaseValue.user_permissions\n )\n }\n }\n\n return camelCase\n}\n","'use client'\n\nimport React, {useCallback, useEffect, useReducer} from \"react\"\nimport {doesLocalStorageMatch, hasWindow, isEqual, saveUserToLocalStorage, USER_INFO_KEY} from \"./utils\";\nimport {useRouter} from \"next/navigation.js\";\nimport {User} from \"./useUser\";\nimport {toOrgIdToOrgMemberInfo} from \"../user\";\n\nexport interface RedirectToSignupOptions {\n postSignupRedirectPath: string;\n}\nexport interface RedirectToLoginOptions {\n postLoginRedirectPath: string;\n}\n\ninterface InternalAuthState {\n loading: boolean\n userAndAccessToken: UserAndAccessToken\n\n logout: () => Promise<void>\n\n redirectToLoginPage: (opts?: RedirectToLoginOptions) => void\n redirectToSignupPage: (opts?: RedirectToSignupOptions) => void\n redirectToAccountPage: () => void\n redirectToOrgPage: (orgId?: string) => void\n redirectToCreateOrgPage: () => void\n redirectToSetupSAMLPage: (orgId: string) => void\n\n getSignupPageUrl(opts?: RedirectToSignupOptions): string\n getLoginPageUrl(opts?: RedirectToLoginOptions): string\n getAccountPageUrl(): string\n getOrgPageUrl(orgId?: string): string\n getCreateOrgPageUrl(): string\n getSetupSAMLPageUrl(orgId: string): string\n\n refreshAuthInfo: () => Promise<User | undefined>\n}\n\nexport type AuthProviderProps = {\n authUrl: string\n reloadOnAuthChange?: boolean\n children?: React.ReactNode\n}\n\nexport const AuthContext = React.createContext<InternalAuthState | undefined>(undefined)\n\ntype UserAndAccessToken = {\n user: User\n accessToken: string\n} | {\n user: undefined\n accessToken: undefined\n}\n\ntype AuthState = {\n loading: boolean\n userAndAccessToken: UserAndAccessToken\n\n // There's no good way to trigger server components to reload outside of router.refresh()\n // This is our workaround until the app router has something better\n authChangeDetected: boolean\n}\n\nconst initialAuthState = {\n loading: true,\n userAndAccessToken: {\n user: undefined,\n accessToken: undefined,\n },\n authChangeDetected: false,\n}\n\ntype AuthStateAction = {\n user: User\n accessToken: string\n} | {\n user: undefined\n accessToken: undefined\n}\n\nfunction authStateReducer(_state: AuthState, action: AuthStateAction): AuthState {\n const newUserForEqualityChecking = {...action.user, lastActiveAt: undefined}\n const existingUserForEqualityChecking = {..._state.userAndAccessToken.user, lastActiveAt: undefined}\n const authChangeDetected = !_state.loading && !isEqual(newUserForEqualityChecking, existingUserForEqualityChecking)\n\n if (!action.user) {\n return {\n loading: false,\n userAndAccessToken: {\n user: undefined,\n accessToken: undefined,\n },\n authChangeDetected,\n }\n } else if (_state.loading) {\n return {\n loading: false,\n userAndAccessToken: {\n user: action.user,\n accessToken: action.accessToken,\n },\n authChangeDetected,\n }\n } else {\n return {\n loading: false,\n userAndAccessToken: {\n user: action.user,\n accessToken: action.accessToken,\n },\n authChangeDetected\n }\n }\n}\n\nexport const AuthProvider = (props: AuthProviderProps) => {\n const [authState, dispatchInner] = useReducer(authStateReducer, initialAuthState)\n const router = useRouter()\n const reloadOnAuthChange = props.reloadOnAuthChange ?? true\n\n const dispatch = useCallback((action: AuthStateAction) => {\n dispatchInner(action)\n saveUserToLocalStorage(action.user)\n }, [dispatchInner])\n\n // This is because we don't have a good way to trigger server components to reload outside of router.refresh()\n // Once server actions isn't alpha, we can hopefully use that instead\n useEffect(() => {\n if (reloadOnAuthChange && authState.authChangeDetected) {\n router.refresh()\n }\n }, [authState.authChangeDetected, reloadOnAuthChange, router])\n\n // Trigger an initial refresh\n useEffect(() => {\n let didCancel = false\n\n async function refreshAuthInfo() {\n const action = await apiGetUserInfo()\n if (!didCancel) {\n dispatch(action)\n }\n }\n\n refreshAuthInfo()\n return () => {\n didCancel = true\n }\n }, [])\n\n\n // Periodically refresh the token\n useEffect(() => {\n let didCancel = false\n\n async function refreshToken() {\n const action = await apiGetUserInfo()\n if (!didCancel) {\n dispatch(action)\n }\n }\n\n async function onStorageEvent(event: StorageEvent) {\n if (event.key === USER_INFO_KEY && !doesLocalStorageMatch(event.newValue, authState.userAndAccessToken.user)) {\n await refreshToken()\n }\n }\n\n // TODO: Retry logic if the request fails\n const interval = setInterval(refreshToken, 5 * 60 * 1000)\n\n if (hasWindow()) {\n window.addEventListener(\"storage\", onStorageEvent)\n window.addEventListener(\"online\", refreshToken)\n window.addEventListener(\"focus\", refreshToken)\n }\n\n return () => {\n didCancel = true\n clearInterval(interval)\n if (hasWindow()) {\n window.removeEventListener(\"storage\", onStorageEvent)\n window.removeEventListener(\"online\", refreshToken)\n window.removeEventListener(\"focus\", refreshToken)\n }\n }\n }, [dispatch, authState.userAndAccessToken.user])\n\n\n const logout = useCallback(async () => {\n await fetch(\"/api/auth/logout\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n credentials: \"include\",\n })\n dispatch({user: undefined, accessToken: undefined})\n }, [dispatch])\n\n const getLoginPageUrl = (opts?: RedirectToLoginOptions) => {\n if (opts?.postLoginRedirectPath) {\n return `/api/auth/login?return_to_path=${encodeURIComponent(opts.postLoginRedirectPath)}`\n }\n\n return \"/api/auth/login\"\n }\n const getSignupPageUrl = (opts?: RedirectToSignupOptions) => {\n if (opts?.postSignupRedirectPath) {\n return `/api/auth/signup?return_to_path=${encodeURIComponent(opts.postSignupRedirectPath)}`\n }\n\n return \"/api/auth/signup\"\n }\n const getAccountPageUrl = useCallback(() => {\n return `${props.authUrl}/account`\n }, [props.authUrl])\n const getOrgPageUrl = useCallback(\n (orgId?: string) => {\n if (orgId) {\n return `${props.authUrl}/org?id=${orgId}`\n } else {\n return `${props.authUrl}/org`\n }\n },\n [props.authUrl]\n )\n const getCreateOrgPageUrl = useCallback(() => {\n return `${props.authUrl}/create_org`\n }, [props.authUrl])\n\n const getSetupSAMLPageUrl = useCallback(\n (orgId: string) => {\n return `${props.authUrl}/saml?id=${orgId}`\n },\n [props.authUrl]\n )\n\n const redirectTo = (url: string) => {\n window.location.href = url\n }\n\n const redirectToLoginPage = (opts?: RedirectToLoginOptions) => redirectTo(getLoginPageUrl(opts))\n const redirectToSignupPage = (opts?: RedirectToSignupOptions) => redirectTo(getSignupPageUrl(opts))\n const redirectToAccountPage = () => redirectTo(getAccountPageUrl())\n const redirectToOrgPage = (orgId?: string) => redirectTo(getOrgPageUrl(orgId))\n const redirectToCreateOrgPage = () => redirectTo(getCreateOrgPageUrl())\n const redirectToSetupSAMLPage = (orgId: string) => redirectTo(getSetupSAMLPageUrl(orgId))\n\n const refreshAuthInfo = async () => {\n const action = await apiGetUserInfo()\n dispatch(action)\n return action.user\n }\n\n const value = {\n loading: authState.loading,\n userAndAccessToken: authState.userAndAccessToken,\n logout,\n redirectToLoginPage,\n redirectToSignupPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n redirectToSetupSAMLPage,\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n refreshAuthInfo,\n }\n return <AuthContext.Provider value={value}>{props.children}</AuthContext.Provider>\n}\n\ntype UserInfoResponse = {\n user: User\n accessToken: string\n} | {\n user: undefined\n accessToken: undefined\n}\n\nasync function apiGetUserInfo(): Promise<UserInfoResponse> {\n try {\n const userInfoResponse = await fetch(\"/api/auth/userinfo\", {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n credentials: \"include\",\n })\n\n if (userInfoResponse.ok) {\n const {userinfo, accessToken, impersonatorUserId} = await userInfoResponse.json()\n const user = new User({\n userId: userinfo.user_id,\n email: userinfo.email,\n emailConfirmed: userinfo.email_confirmed,\n hasPassword: userinfo.has_password,\n username: userinfo.username,\n firstName: userinfo.first_name,\n lastName: userinfo.last_name,\n pictureUrl: userinfo.picture_url,\n orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),\n mfaEnabled: userinfo.mfa_enabled,\n canCreateOrgs: userinfo.can_create_orgs,\n updatePasswordRequired: userinfo.update_password_required,\n createdAt: userinfo.created_at,\n lastActiveAt: userinfo.last_active_at,\n properties: userinfo.properties,\n impersonatorUserId,\n })\n\n return {user, accessToken}\n } else if (userInfoResponse.status === 401) {\n return {user: undefined, accessToken: undefined}\n } else {\n console.info(\"Failed to refresh token\", userInfoResponse)\n }\n } catch (e) {\n console.info(\"Failed to refresh token\", e)\n }\n throw new Error(\"Failed to refresh token\")\n}\n","import {UserFromToken} from \"../user\";\nimport {User} from \"./useUser\";\n\nexport const USER_INFO_KEY = \"__PROPEL_AUTH_USER_INFO\"\n\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\"\n}\n\nexport function saveUserToLocalStorage(user: User | undefined) {\n if (user) {\n localStorage.setItem(USER_INFO_KEY, JSON.stringify(user))\n } else {\n localStorage.setItem(USER_INFO_KEY, \"{}\")\n }\n}\n\nexport function doesLocalStorageMatch(newValue: string | null, user: UserFromToken | undefined): boolean {\n if (!newValue) {\n return false\n } else if (!user) {\n return newValue === \"{}\"\n }\n\n const parsed = JSON.parse(newValue)\n if (!parsed) {\n return false\n }\n\n return isEqual(parsed, user)\n}\n\nexport function isEqual(a: any, b: any): boolean {\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) !== Array.isArray(b)) {\n return false\n }\n\n if (Array.isArray(a)) {\n const aArray = a as any[]\n const bArray = b as any[]\n if (aArray.length !== bArray.length) {\n return false\n }\n\n for (let i = 0; i < aArray.length; i++) {\n if (!isEqual(aArray[i], bArray[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (typeof a === \"object\") {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) {\n return false\n }\n\n for (const key of aKeys) {\n if (!isEqual(a[key], b[key])) {\n return false\n }\n }\n\n return true\n } else {\n return a === b\n }\n}","'use client'\n\nimport {useContext} from \"react\"\nimport {AuthContext} from \"./AuthProvider\"\nimport {OrgIdToOrgMemberInfo, OrgMemberInfo} from \"../user\";\n\nexport class User {\n public userId: string\n public email: string\n public emailConfirmed: boolean\n public hasPassword: boolean\n\n public username?: string\n public firstName?: string\n public lastName?: string\n public pictureUrl?: string\n\n public orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n\n public mfaEnabled: boolean\n public canCreateOrgs: boolean\n public updatePasswordRequired: boolean\n\n public createdAt: number\n public lastActiveAt: number\n\n public properties?: {[key: string]: unknown}\n\n public legacyUserId?: string\n public impersonatorUserId?: string\n\n constructor({\n userId,\n email,\n emailConfirmed,\n hasPassword,\n username,\n firstName,\n lastName,\n pictureUrl,\n orgIdToOrgMemberInfo,\n mfaEnabled,\n canCreateOrgs,\n updatePasswordRequired,\n createdAt,\n lastActiveAt,\n legacyUserId,\n properties,\n impersonatorUserId,\n }: {\n userId: string\n email: string\n emailConfirmed: boolean\n hasPassword: boolean\n username?: string\n firstName?: string\n lastName?: string\n pictureUrl?: string\n orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n mfaEnabled: boolean\n canCreateOrgs: boolean\n updatePasswordRequired: boolean\n createdAt: number\n lastActiveAt: number\n legacyUserId?: string\n properties?: {[key: string]: unknown}\n impersonatorUserId?: string\n }) {\n this.userId = userId\n this.email = email\n this.emailConfirmed = emailConfirmed\n this.hasPassword = hasPassword\n this.username = username\n this.firstName = firstName\n this.lastName = lastName\n this.pictureUrl = pictureUrl\n this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo\n this.mfaEnabled = mfaEnabled\n this.canCreateOrgs = canCreateOrgs\n this.updatePasswordRequired = updatePasswordRequired\n this.createdAt = createdAt\n this.lastActiveAt = lastActiveAt\n this.legacyUserId = legacyUserId\n this.properties = properties\n this.impersonatorUserId = impersonatorUserId\n }\n\n public getOrg(orgId: string): OrgMemberInfo | undefined {\n return this.orgIdToOrgMemberInfo?.[orgId]\n }\n\n public getOrgByName(orgName: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n const urlSafeOrgName = orgName.toLowerCase().replace(/ /g, \"-\")\n for (const orgId in this.orgIdToOrgMemberInfo) {\n const orgMemberInfo = this.orgIdToOrgMemberInfo[orgId]\n if (orgMemberInfo.urlSafeOrgName === urlSafeOrgName) {\n return orgMemberInfo\n }\n }\n\n return undefined\n }\n\n public getOrgs(): OrgMemberInfo[] {\n if (!this.orgIdToOrgMemberInfo) {\n return []\n }\n\n return Object.values(this.orgIdToOrgMemberInfo)\n }\n\n public isImpersonating(): boolean {\n return !!this.impersonatorUserId\n }\n}\n\nexport type UseUserLoading = {\n loading: true\n isLoggedIn: never\n user: never\n accessToken: never\n}\n\nexport type UseUserLoggedIn = {\n loading: false\n isLoggedIn: true\n user: User\n accessToken: string\n}\n\nexport type UseUserNotLoggedIn = {\n loading: false\n isLoggedIn: false\n user: undefined\n accessToken: undefined\n}\n\nexport type UseUser = UseUserLoading | UseUserLoggedIn | UseUserNotLoggedIn\n\nexport function useUser(): UseUser {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useUser must be used within an AuthProvider\")\n }\n\n const {loading, userAndAccessToken} = context\n if (loading) {\n return {\n loading: true,\n isLoggedIn: undefined as never,\n user: undefined as never,\n accessToken: undefined as never,\n }\n } else if (userAndAccessToken.user) {\n return {\n loading: false,\n isLoggedIn: true,\n user: userAndAccessToken.user,\n accessToken: userAndAccessToken.accessToken,\n }\n } else {\n return {\n loading: false,\n isLoggedIn: false,\n user: undefined,\n accessToken: undefined,\n }\n }\n}","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useHostedPageUrls() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useHostedPageUrls must be used within an AuthProvider\")\n }\n const {\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n } = context\n return {\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n }\n}\n","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useLogoutFunction() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useLogoutFunction must be used within an AuthProvider\")\n }\n const { logout } = context\n return logout\n}\n","import React, { useContext, useEffect } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useRedirectFunctions() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useRedirectFunctions must be used within an AuthProvider\")\n }\n const {\n redirectToAccountPage,\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n } = context\n return {\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n }\n}\n\nexport interface RedirectProps {\n children?: React.ReactNode\n}\n\nexport function RedirectToSignup({ children }: RedirectProps) {\n const { redirectToSignupPage } = useRedirectFunctions()\n\n useEffect(() => {\n redirectToSignupPage()\n }, [])\n\n return <>{children}</>\n}\n\nexport function RedirectToLogin({ children }: RedirectProps) {\n const { redirectToLoginPage } = useRedirectFunctions()\n useEffect(() => {\n redirectToLoginPage()\n }, [])\n return <>{children}</>\n}\n","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useRefreshAuth() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useRefreshAuth must be used within an AuthProvider\")\n }\n const { refreshAuthInfo } = context\n return refreshAuthInfo\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,gBAAN,MAAoB;AAAA,EAgBvB,YACI,QACA,OACA,sBACA,WACA,UACA,UACA,cACA,oBACA,YACF;AACE,SAAK,SAAS;AACd,SAAK,uBAAuB;AAE5B,SAAK,QAAQ;AACb,SAAK,YAAY;AACjB,SAAK,WAAW;AAChB,SAAK,WAAW;AAEhB,SAAK,eAAe;AACpB,SAAK,qBAAqB;AAE1B,SAAK,aAAa;AAAA,EACtB;AAAA,EAEO,OAAO,OAA0C;AACpD,QAAI,CAAC,KAAK,sBAAsB;AAC5B,aAAO;AAAA,IACX;AAEA,WAAO,KAAK,qBAAqB,KAAK;AAAA,EAC1C;AAAA,EAEO,aAAa,SAA4C;AAC5D,QAAI,CAAC,KAAK,sBAAsB;AAC5B,aAAO;AAAA,IACX;AAEA,UAAM,iBAAiB,QAAQ,YAAY,EAAE,QAAQ,M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;;;ACVA,OAAOC,UAAS,cAAAC,aAAY,aAAAC,kBAAiB;AAGtC,SAAS,uBAAuB;AACnC,QAAM,UAAUC,YAAW,WAAW;AACtC,MAAI,YAAY,QAAW;AACvB,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC9E;AACA,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AACJ,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;AAMO,SAAS,iBAAiB,EAAE,SAAS,GAAkB;AAC1D,QAAM,EAAE,qBAAqB,IAAI,qBAAqB;AAEtD,EAAAC,WAAU,MAAM;AACZ,yBAAqB;AAAA,EACzB,GAAG,CAAC,CAAC;AAEL,SAAO,gBAAAC,OAAA,cAAAA,OAAA,gBAAG,QAAS;AACvB;AAEO,SAAS,gBAAgB,EAAE,SAAS,GAAkB;AACzD,QAAM,EAAE,oBAAoB,IAAI,qBAAqB;AACrD,EAAAD,WAAU,MAAM;AACZ,wBAAoB;AAAA,EACxB,GAAG,CAAC,CAAC;AACL,SAAO,gBAAAC,OAAA,cAAAA,OAAA,gBAAG,QAAS;AACvB;;;AC5CA,SAAS,cAAAC,mBAAkB;AAGpB,SAAS,iBAAiB;AAC7B,QAAM,UAAUC,YAAW,WAAW;AACtC,MAAI,YAAY,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACxE;AACA,QAAM,EAAE,gBAAgB,IAAI;AAC5B,SAAO;AACX;","names":["refreshAuthInfo","useContext","useContext","useContext","useContext","React","useContext","useEffect","useContext","useEffect","React","useContext","useContext"]}
|
1
|
+
{"version":3,"sources":["../../src/user.ts","../../src/client/AuthProvider.tsx","../../src/client/utils.ts","../../src/client/useUser.tsx","../../src/client/useHostedPageUrls.tsx","../../src/client/useLogoutFunction.ts","../../src/client/useRedirectFunctions.tsx","../../src/client/useRefreshAuth.ts"],"sourcesContent":["export class UserFromToken {\n public userId: string\n\n public activeOrgId?: string\n public orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n\n // Metadata about the user\n public email: string\n public firstName?: string\n public lastName?: string\n public username?: string\n public properties?: { [key: string]: unknown }\n\n // If you used our migration APIs to migrate this user from a different system,\n // this is their original ID from that system.\n public legacyUserId?: string\n public impersonatorUserId?: string\n\n constructor(\n userId: string,\n email: string,\n orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo,\n firstName?: string,\n lastName?: string,\n username?: string,\n legacyUserId?: string,\n impersonatorUserId?: string,\n properties?: { [key: string]: unknown },\n activeOrgId?: string\n ) {\n this.userId = userId\n\n this.activeOrgId = activeOrgId\n this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo\n\n this.email = email\n this.firstName = firstName\n this.lastName = lastName\n this.username = username\n\n this.legacyUserId = legacyUserId\n this.impersonatorUserId = impersonatorUserId\n\n this.properties = properties\n }\n\n public getActiveOrg(): OrgMemberInfo | undefined {\n if (!this.activeOrgId || !this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n return this.orgIdToOrgMemberInfo[this.activeOrgId]\n }\n\n public getActiveOrgId(): string | undefined {\n return this.activeOrgId\n }\n\n public getOrg(orgId: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n return this.orgIdToOrgMemberInfo[orgId]\n }\n\n public getOrgByName(orgName: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n const urlSafeOrgName = orgName.toLowerCase().replace(/ /g, '-')\n for (const orgId in this.orgIdToOrgMemberInfo) {\n const orgMemberInfo = this.orgIdToOrgMemberInfo[orgId]\n if (orgMemberInfo.urlSafeOrgName === urlSafeOrgName) {\n return orgMemberInfo\n }\n }\n\n return undefined\n }\n\n public getOrgs(): OrgMemberInfo[] {\n if (!this.orgIdToOrgMemberInfo) {\n return []\n }\n\n return Object.values(this.orgIdToOrgMemberInfo)\n }\n\n public isImpersonating(): boolean {\n return !!this.impersonatorUserId\n }\n\n public static fromJSON(json: string): UserFromToken {\n const obj = JSON.parse(json)\n const orgIdToOrgMemberInfo: OrgIdToOrgMemberInfo = {}\n for (const orgId in obj.orgIdToOrgMemberInfo) {\n orgIdToOrgMemberInfo[orgId] = OrgMemberInfo.fromJSON(JSON.stringify(obj.orgIdToOrgMemberInfo[orgId]))\n }\n return new UserFromToken(\n obj.userId,\n obj.email,\n orgIdToOrgMemberInfo,\n obj.firstName,\n obj.lastName,\n obj.username,\n obj.legacyUserId,\n obj.impersonatorUserId,\n obj.properties\n )\n }\n\n public static fromJwtPayload(payload: InternalUser): UserFromToken {\n let activeOrgId: string | undefined\n let orgIdToOrgMemberInfo: OrgIdToOrgMemberInfo | undefined\n\n if (payload.org_member_info) {\n activeOrgId = payload.org_member_info.org_id\n orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo({ [activeOrgId]: payload.org_member_info })\n } else {\n activeOrgId = undefined\n orgIdToOrgMemberInfo = toOrgIdToOrgMemberInfo(payload.org_id_to_org_member_info)\n }\n\n return new UserFromToken(\n payload.user_id,\n payload.email,\n orgIdToOrgMemberInfo,\n payload.first_name,\n payload.last_name,\n payload.username,\n payload.legacy_user_id,\n payload.impersonatorUserId,\n payload.properties,\n activeOrgId\n )\n }\n}\n\nexport type OrgIdToOrgMemberInfo = {\n [orgId: string]: OrgMemberInfo\n}\n\nexport class OrgMemberInfo {\n public orgId: string\n public orgName: string\n public orgMetadata: { [key: string]: any }\n public urlSafeOrgName: string\n\n public userAssignedRole: string\n public userInheritedRolesPlusCurrentRole: string[]\n public userPermissions: string[]\n\n constructor(\n orgId: string,\n orgName: string,\n orgMetadata: { [key: string]: any },\n urlSafeOrgName: string,\n userAssignedRole: string,\n userInheritedRolesPlusCurrentRole: string[],\n userPermissions: string[]\n ) {\n this.orgId = orgId\n this.orgName = orgName\n this.orgMetadata = orgMetadata\n this.urlSafeOrgName = urlSafeOrgName\n\n this.userAssignedRole = userAssignedRole\n this.userInheritedRolesPlusCurrentRole = userInheritedRolesPlusCurrentRole\n this.userPermissions = userPermissions\n }\n\n // validation methods\n\n public isRole(role: string): boolean {\n return this.userAssignedRole === role\n }\n\n public isAtLeastRole(role: string): boolean {\n return this.userInheritedRolesPlusCurrentRole.includes(role)\n }\n\n public hasPermission(permission: string): boolean {\n return this.userPermissions.includes(permission)\n }\n\n public hasAllPermissions(permissions: string[]): boolean {\n return permissions.every((permission) => this.hasPermission(permission))\n }\n\n public static fromJSON(json: string): OrgMemberInfo {\n const obj = JSON.parse(json)\n return new OrgMemberInfo(\n obj.orgId,\n obj.orgName,\n obj.orgMetadata,\n obj.urlSafeOrgName,\n obj.userAssignedRole,\n obj.userInheritedRolesPlusCurrentRole,\n obj.userPermissions\n )\n }\n\n // getters for the private fields\n\n get assignedRole(): string {\n return this.userAssignedRole\n }\n\n get inheritedRolesPlusCurrentRole(): string[] {\n return this.userInheritedRolesPlusCurrentRole\n }\n\n get permissions(): string[] {\n return this.userPermissions\n }\n}\n\n// These Internal types exist since the server returns snake case, but typescript/javascript\n// convention is camelCase.\nexport type InternalOrgMemberInfo = {\n org_id: string\n org_name: string\n org_metadata: { [key: string]: any }\n url_safe_org_name: string\n user_role: string\n inherited_user_roles_plus_current_role: string[]\n user_permissions: string[]\n}\nexport type InternalUser = {\n user_id: string\n\n org_member_info?: InternalOrgMemberInfo\n org_id_to_org_member_info?: { [org_id: string]: InternalOrgMemberInfo }\n\n email: string\n first_name?: string\n last_name?: string\n username?: string\n properties?: { [key: string]: unknown }\n\n // If you used our migration APIs to migrate this user from a different system, this is their original ID from that system.\n legacy_user_id?: string\n impersonatorUserId?: string\n}\n\nexport function toUser(snake_case: InternalUser): UserFromToken {\n return UserFromToken.fromJwtPayload(snake_case)\n}\n\nexport function toOrgIdToOrgMemberInfo(snake_case?: {\n [org_id: string]: InternalOrgMemberInfo\n}): OrgIdToOrgMemberInfo | undefined {\n if (snake_case === undefined) {\n return undefined\n }\n const camelCase: OrgIdToOrgMemberInfo = {}\n\n for (const key of Object.keys(snake_case)) {\n const snakeCaseValue = snake_case[key]\n if (snakeCaseValue) {\n camelCase[key] = new OrgMemberInfo(\n snakeCaseValue.org_id,\n snakeCaseValue.org_name,\n snakeCaseValue.org_metadata,\n snakeCaseValue.url_safe_org_name,\n snakeCaseValue.user_role,\n snakeCaseValue.inherited_user_roles_plus_current_role,\n snakeCaseValue.user_permissions\n )\n }\n }\n\n return camelCase\n}\n","'use client'\n\nimport React, { useCallback, useEffect, useReducer } from 'react'\nimport { doesLocalStorageMatch, hasWindow, isEqual, saveUserToLocalStorage, USER_INFO_KEY } from './utils'\nimport { useRouter } from 'next/navigation.js'\nimport { User } from './useUser'\nimport { toOrgIdToOrgMemberInfo } from '../user'\n\nexport interface RedirectToSignupOptions {\n postSignupRedirectPath: string\n}\nexport interface RedirectToLoginOptions {\n postLoginRedirectPath: string\n}\n\ninterface InternalAuthState {\n loading: boolean\n userAndAccessToken: UserAndAccessToken\n\n logout: () => Promise<void>\n\n redirectToLoginPage: (opts?: RedirectToLoginOptions) => void\n redirectToSignupPage: (opts?: RedirectToSignupOptions) => void\n redirectToAccountPage: () => void\n redirectToOrgPage: (orgId?: string) => void\n redirectToCreateOrgPage: () => void\n redirectToSetupSAMLPage: (orgId: string) => void\n\n getSignupPageUrl(opts?: RedirectToSignupOptions): string\n getLoginPageUrl(opts?: RedirectToLoginOptions): string\n getAccountPageUrl(): string\n getOrgPageUrl(orgId?: string): string\n getCreateOrgPageUrl(): string\n getSetupSAMLPageUrl(orgId: string): string\n\n refreshAuthInfo: () => Promise<User | undefined>\n setActiveOrg: (orgId: string) => Promise<User | undefined>\n}\n\nexport type AuthProviderProps = {\n authUrl: string\n reloadOnAuthChange?: boolean\n children?: React.ReactNode\n}\n\nexport const AuthContext = React.createContext<InternalAuthState | undefined>(undefined)\n\ntype UserAndAccessToken =\n | {\n user: User\n accessToken: string\n }\n | {\n user: undefined\n accessToken: undefined\n }\n\ntype AuthState = {\n loading: boolean\n userAndAccessToken: UserAndAccessToken\n\n // There's no good way to trigger server components to reload outside of router.refresh()\n // This is our workaround until the app router has something better\n authChangeDetected: boolean\n}\n\nconst initialAuthState = {\n loading: true,\n userAndAccessToken: {\n user: undefined,\n accessToken: undefined,\n },\n authChangeDetected: false,\n}\n\ntype AuthStateAction =\n | {\n user: User\n accessToken: string\n }\n | {\n user: undefined\n accessToken: undefined\n }\n\nfunction authStateReducer(_state: AuthState, action: AuthStateAction): AuthState {\n const newUserForEqualityChecking = { ...action.user, lastActiveAt: undefined }\n const existingUserForEqualityChecking = { ..._state.userAndAccessToken.user, lastActiveAt: undefined }\n const authChangeDetected = !_state.loading && !isEqual(newUserForEqualityChecking, existingUserForEqualityChecking)\n\n if (!action.user) {\n return {\n loading: false,\n userAndAccessToken: {\n user: undefined,\n accessToken: undefined,\n },\n authChangeDetected,\n }\n } else if (_state.loading) {\n return {\n loading: false,\n userAndAccessToken: {\n user: action.user,\n accessToken: action.accessToken,\n },\n authChangeDetected,\n }\n } else {\n return {\n loading: false,\n userAndAccessToken: {\n user: action.user,\n accessToken: action.accessToken,\n },\n authChangeDetected,\n }\n }\n}\n\nexport const AuthProvider = (props: AuthProviderProps) => {\n const [authState, dispatchInner] = useReducer(authStateReducer, initialAuthState)\n const router = useRouter()\n const reloadOnAuthChange = props.reloadOnAuthChange ?? true\n\n const dispatch = useCallback(\n (action: AuthStateAction) => {\n dispatchInner(action)\n saveUserToLocalStorage(action.user)\n },\n [dispatchInner]\n )\n\n // This is because we don't have a good way to trigger server components to reload outside of router.refresh()\n // Once server actions isn't alpha, we can hopefully use that instead\n useEffect(() => {\n if (reloadOnAuthChange && authState.authChangeDetected) {\n router.refresh()\n }\n }, [authState.authChangeDetected, reloadOnAuthChange, router])\n\n // Trigger an initial refresh\n useEffect(() => {\n let didCancel = false\n\n async function refreshAuthInfo() {\n const action = await apiGetUserInfo()\n if (!didCancel) {\n dispatch(action)\n }\n }\n\n refreshAuthInfo()\n return () => {\n didCancel = true\n }\n }, [])\n\n // Periodically refresh the token\n useEffect(() => {\n let didCancel = false\n\n async function refreshToken() {\n const action = await apiGetUserInfo()\n if (!didCancel) {\n dispatch(action)\n }\n }\n\n async function onStorageEvent(event: StorageEvent) {\n if (\n event.key === USER_INFO_KEY &&\n !doesLocalStorageMatch(event.newValue, authState.userAndAccessToken.user)\n ) {\n await refreshToken()\n }\n }\n\n // TODO: Retry logic if the request fails\n const interval = setInterval(refreshToken, 5 * 60 * 1000)\n\n if (hasWindow()) {\n window.addEventListener('storage', onStorageEvent)\n window.addEventListener('online', refreshToken)\n window.addEventListener('focus', refreshToken)\n }\n\n return () => {\n didCancel = true\n clearInterval(interval)\n if (hasWindow()) {\n window.removeEventListener('storage', onStorageEvent)\n window.removeEventListener('online', refreshToken)\n window.removeEventListener('focus', refreshToken)\n }\n }\n }, [dispatch, authState.userAndAccessToken.user])\n\n const logout = useCallback(async () => {\n await fetch('/api/auth/logout', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n credentials: 'include',\n })\n dispatch({ user: undefined, accessToken: undefined })\n }, [dispatch])\n\n const getLoginPageUrl = (opts?: RedirectToLoginOptions) => {\n if (opts?.postLoginRedirectPath) {\n return `/api/auth/login?return_to_path=${encodeURIComponent(opts.postLoginRedirectPath)}`\n }\n\n return '/api/auth/login'\n }\n const getSignupPageUrl = (opts?: RedirectToSignupOptions) => {\n if (opts?.postSignupRedirectPath) {\n return `/api/auth/signup?return_to_path=${encodeURIComponent(opts.postSignupRedirectPath)}`\n }\n\n return '/api/auth/signup'\n }\n const getAccountPageUrl = useCallback(() => {\n return `${props.authUrl}/account`\n }, [props.authUrl])\n const getOrgPageUrl = useCallback(\n (orgId?: string) => {\n if (orgId) {\n return `${props.authUrl}/org?id=${orgId}`\n } else {\n return `${props.authUrl}/org`\n }\n },\n [props.authUrl]\n )\n const getCreateOrgPageUrl = useCallback(() => {\n return `${props.authUrl}/create_org`\n }, [props.authUrl])\n\n const getSetupSAMLPageUrl = useCallback(\n (orgId: string) => {\n return `${props.authUrl}/saml?id=${orgId}`\n },\n [props.authUrl]\n )\n\n const redirectTo = (url: string) => {\n window.location.href = url\n }\n\n const redirectToLoginPage = (opts?: RedirectToLoginOptions) => redirectTo(getLoginPageUrl(opts))\n const redirectToSignupPage = (opts?: RedirectToSignupOptions) => redirectTo(getSignupPageUrl(opts))\n const redirectToAccountPage = () => redirectTo(getAccountPageUrl())\n const redirectToOrgPage = (orgId?: string) => redirectTo(getOrgPageUrl(orgId))\n const redirectToCreateOrgPage = () => redirectTo(getCreateOrgPageUrl())\n const redirectToSetupSAMLPage = (orgId: string) => redirectTo(getSetupSAMLPageUrl(orgId))\n\n const refreshAuthInfo = useCallback(async () => {\n const action = await apiGetUserInfo()\n dispatch(action)\n return action.user\n }, [dispatch])\n\n const setActiveOrg = useCallback(\n async (orgId: string) => {\n const action = await apiPostSetActiveOrg(orgId)\n if (action.error === 'not_in_org') {\n return undefined\n } else {\n dispatch(action)\n return action.user\n }\n },\n [dispatch]\n )\n\n const value = {\n loading: authState.loading,\n userAndAccessToken: authState.userAndAccessToken,\n logout,\n redirectToLoginPage,\n redirectToSignupPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n redirectToSetupSAMLPage,\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n refreshAuthInfo,\n setActiveOrg,\n }\n return <AuthContext.Provider value={value}>{props.children}</AuthContext.Provider>\n}\n\ntype UserInfoResponse =\n | {\n user: User\n accessToken: string\n }\n | {\n user: undefined\n accessToken: undefined\n }\n\nasync function apiGetUserInfo(): Promise<UserInfoResponse> {\n try {\n const userInfoResponse = await fetch('/api/auth/userinfo', {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n credentials: 'include',\n })\n\n if (userInfoResponse.ok) {\n const { userinfo, accessToken, impersonatorUserId, activeOrgId } = await userInfoResponse.json()\n const user = new User({\n userId: userinfo.user_id,\n email: userinfo.email,\n emailConfirmed: userinfo.email_confirmed,\n hasPassword: userinfo.has_password,\n username: userinfo.username,\n firstName: userinfo.first_name,\n lastName: userinfo.last_name,\n pictureUrl: userinfo.picture_url,\n orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),\n activeOrgId,\n mfaEnabled: userinfo.mfa_enabled,\n canCreateOrgs: userinfo.can_create_orgs,\n updatePasswordRequired: userinfo.update_password_required,\n createdAt: userinfo.created_at,\n lastActiveAt: userinfo.last_active_at,\n properties: userinfo.properties,\n impersonatorUserId,\n })\n\n return { user, accessToken }\n } else if (userInfoResponse.status === 401) {\n return { user: undefined, accessToken: undefined }\n } else {\n console.info('Failed to refresh token', userInfoResponse)\n }\n } catch (e) {\n console.info('Failed to refresh token', e)\n }\n throw new Error('Failed to refresh token')\n}\n\ntype SetActiveOrgResponse =\n | {\n user: User\n accessToken: string\n error: undefined\n }\n | {\n error: 'not_in_org'\n }\n\nasync function apiPostSetActiveOrg(orgId: string): Promise<SetActiveOrgResponse> {\n try {\n const queryParams = new URLSearchParams({ active_org_id: orgId }).toString()\n const url = `/api/auth/set-active-org?${queryParams}`\n const userInfoResponse = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n credentials: 'include',\n })\n\n if (userInfoResponse.ok) {\n const { userinfo, accessToken, impersonatorUserId, activeOrgId } = await userInfoResponse.json()\n const user = new User({\n userId: userinfo.user_id,\n email: userinfo.email,\n emailConfirmed: userinfo.email_confirmed,\n hasPassword: userinfo.has_password,\n username: userinfo.username,\n firstName: userinfo.first_name,\n lastName: userinfo.last_name,\n pictureUrl: userinfo.picture_url,\n orgIdToOrgMemberInfo: toOrgIdToOrgMemberInfo(userinfo.org_id_to_org_info),\n activeOrgId,\n mfaEnabled: userinfo.mfa_enabled,\n canCreateOrgs: userinfo.can_create_orgs,\n updatePasswordRequired: userinfo.update_password_required,\n createdAt: userinfo.created_at,\n lastActiveAt: userinfo.last_active_at,\n properties: userinfo.properties,\n impersonatorUserId,\n })\n\n return { user, accessToken, error: undefined }\n } else if (userInfoResponse.status === 401) {\n return { error: 'not_in_org' }\n } else {\n console.info('Failed to set active org', userInfoResponse)\n }\n } catch (e) {\n console.info('Failed to set active org', e)\n }\n throw new Error('Failed to set active org')\n}\n","import {UserFromToken} from \"../user\";\nimport {User} from \"./useUser\";\n\nexport const USER_INFO_KEY = \"__PROPEL_AUTH_USER_INFO\"\n\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\"\n}\n\nexport function saveUserToLocalStorage(user: User | undefined) {\n if (user) {\n localStorage.setItem(USER_INFO_KEY, JSON.stringify(user))\n } else {\n localStorage.setItem(USER_INFO_KEY, \"{}\")\n }\n}\n\nexport function doesLocalStorageMatch(newValue: string | null, user: UserFromToken | undefined): boolean {\n if (!newValue) {\n return false\n } else if (!user) {\n return newValue === \"{}\"\n }\n\n const parsed = JSON.parse(newValue)\n if (!parsed) {\n return false\n }\n\n return isEqual(parsed, user)\n}\n\nexport function isEqual(a: any, b: any): boolean {\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) !== Array.isArray(b)) {\n return false\n }\n\n if (Array.isArray(a)) {\n const aArray = a as any[]\n const bArray = b as any[]\n if (aArray.length !== bArray.length) {\n return false\n }\n\n for (let i = 0; i < aArray.length; i++) {\n if (!isEqual(aArray[i], bArray[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (typeof a === \"object\") {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) {\n return false\n }\n\n for (const key of aKeys) {\n if (!isEqual(a[key], b[key])) {\n return false\n }\n }\n\n return true\n } else {\n return a === b\n }\n}","'use client'\n\nimport { useContext } from 'react'\nimport { AuthContext } from './AuthProvider'\nimport { OrgIdToOrgMemberInfo, OrgMemberInfo } from '../user'\n\nexport class User {\n public userId: string\n public email: string\n public emailConfirmed: boolean\n public hasPassword: boolean\n\n public username?: string\n public firstName?: string\n public lastName?: string\n public pictureUrl?: string\n\n public orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n public activeOrgId?: string\n\n public mfaEnabled: boolean\n public canCreateOrgs: boolean\n public updatePasswordRequired: boolean\n\n public createdAt: number\n public lastActiveAt: number\n\n public properties?: { [key: string]: unknown }\n\n public legacyUserId?: string\n public impersonatorUserId?: string\n\n constructor({\n userId,\n email,\n emailConfirmed,\n hasPassword,\n username,\n firstName,\n lastName,\n pictureUrl,\n orgIdToOrgMemberInfo,\n activeOrgId,\n mfaEnabled,\n canCreateOrgs,\n updatePasswordRequired,\n createdAt,\n lastActiveAt,\n legacyUserId,\n properties,\n impersonatorUserId,\n }: {\n userId: string\n email: string\n emailConfirmed: boolean\n hasPassword: boolean\n username?: string\n firstName?: string\n lastName?: string\n pictureUrl?: string\n orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo\n activeOrgId?: string\n mfaEnabled: boolean\n canCreateOrgs: boolean\n updatePasswordRequired: boolean\n createdAt: number\n lastActiveAt: number\n legacyUserId?: string\n properties?: { [key: string]: unknown }\n impersonatorUserId?: string\n }) {\n this.userId = userId\n this.email = email\n this.emailConfirmed = emailConfirmed\n this.hasPassword = hasPassword\n this.username = username\n this.firstName = firstName\n this.lastName = lastName\n this.pictureUrl = pictureUrl\n this.orgIdToOrgMemberInfo = orgIdToOrgMemberInfo\n this.activeOrgId = activeOrgId\n this.mfaEnabled = mfaEnabled\n this.canCreateOrgs = canCreateOrgs\n this.updatePasswordRequired = updatePasswordRequired\n this.createdAt = createdAt\n this.lastActiveAt = lastActiveAt\n this.legacyUserId = legacyUserId\n this.properties = properties\n this.impersonatorUserId = impersonatorUserId\n }\n\n public getActiveOrg(): OrgMemberInfo | undefined {\n if (!this.activeOrgId) {\n return undefined\n }\n return this.getOrg(this.activeOrgId)\n }\n\n public getActiveOrgId(): string | undefined {\n return this.activeOrgId\n }\n\n public getOrg(orgId: string): OrgMemberInfo | undefined {\n return this.orgIdToOrgMemberInfo?.[orgId]\n }\n\n public getOrgByName(orgName: string): OrgMemberInfo | undefined {\n if (!this.orgIdToOrgMemberInfo) {\n return undefined\n }\n\n const urlSafeOrgName = orgName.toLowerCase().replace(/ /g, '-')\n for (const orgId in this.orgIdToOrgMemberInfo) {\n const orgMemberInfo = this.orgIdToOrgMemberInfo[orgId]\n if (orgMemberInfo.urlSafeOrgName === urlSafeOrgName) {\n return orgMemberInfo\n }\n }\n\n return undefined\n }\n\n public getOrgs(): OrgMemberInfo[] {\n if (!this.orgIdToOrgMemberInfo) {\n return []\n }\n\n return Object.values(this.orgIdToOrgMemberInfo)\n }\n\n public isImpersonating(): boolean {\n return !!this.impersonatorUserId\n }\n}\n\nexport type UseUserLoading = {\n loading: true\n isLoggedIn: never\n user: never\n accessToken: never\n setActiveOrg: never\n}\n\nexport type UseUserLoggedIn = {\n loading: false\n isLoggedIn: true\n user: User\n accessToken: string\n setActiveOrg: (orgId: string) => Promise<User | undefined>\n}\n\nexport type UseUserNotLoggedIn = {\n loading: false\n isLoggedIn: false\n user: undefined\n accessToken: undefined\n setActiveOrg: never\n}\n\nexport type UseUser = UseUserLoading | UseUserLoggedIn | UseUserNotLoggedIn\n\nexport function useUser(): UseUser {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error('useUser must be used within an AuthProvider')\n }\n\n const { loading, userAndAccessToken } = context\n if (loading) {\n return {\n loading: true,\n isLoggedIn: undefined as never,\n user: undefined as never,\n accessToken: undefined as never,\n setActiveOrg: undefined as never,\n }\n } else if (userAndAccessToken.user) {\n return {\n loading: false,\n isLoggedIn: true,\n user: userAndAccessToken.user,\n accessToken: userAndAccessToken.accessToken,\n setActiveOrg: context.setActiveOrg,\n }\n } else {\n return {\n loading: false,\n isLoggedIn: false,\n user: undefined,\n accessToken: undefined,\n setActiveOrg: undefined as never,\n }\n }\n}\n","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useHostedPageUrls() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useHostedPageUrls must be used within an AuthProvider\")\n }\n const {\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n } = context\n return {\n getLoginPageUrl,\n getSignupPageUrl,\n getAccountPageUrl,\n getOrgPageUrl,\n getCreateOrgPageUrl,\n getSetupSAMLPageUrl,\n }\n}\n","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useLogoutFunction() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useLogoutFunction must be used within an AuthProvider\")\n }\n const { logout } = context\n return logout\n}\n","import React, { useContext, useEffect } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useRedirectFunctions() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useRedirectFunctions must be used within an AuthProvider\")\n }\n const {\n redirectToAccountPage,\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n } = context\n return {\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n }\n}\n\nexport interface RedirectProps {\n children?: React.ReactNode\n}\n\nexport function RedirectToSignup({ children }: RedirectProps) {\n const { redirectToSignupPage } = useRedirectFunctions()\n\n useEffect(() => {\n redirectToSignupPage()\n }, [])\n\n return <>{children}</>\n}\n\nexport function RedirectToLogin({ children }: RedirectProps) {\n const { redirectToLoginPage } = useRedirectFunctions()\n useEffect(() => {\n redirectToLoginPage()\n }, [])\n return <>{children}</>\n}\n","import { useContext } from \"react\"\nimport { AuthContext } from \"./AuthProvider\"\n\nexport function useRefreshAuth() {\n const context = useContext(AuthContext)\n if (context === undefined) {\n throw new Error(\"useRefreshAuth must be used within an AuthProvider\")\n }\n const { refreshAuthInfo } = context\n return refreshAuthInfo\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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;;;AC5CA,SAAS,cAAAC,mBAAkB;AAGpB,SAAS,iBAAiB;AAC7B,QAAM,UAAUC,YAAW,WAAW;AACtC,MAAI,YAAY,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACxE;AACA,QAAM,EAAE,gBAAgB,IAAI;AAC5B,SAAO;AACX;","names":["refreshAuthInfo","useContext","useContext","useContext","useContext","React","useContext","useEffect","useContext","useEffect","React","useContext","useContext"]}
|
@@ -13,6 +13,7 @@ declare class ConfigurationException extends Error {
|
|
13
13
|
|
14
14
|
declare class UserFromToken {
|
15
15
|
userId: string;
|
16
|
+
activeOrgId?: string;
|
16
17
|
orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo;
|
17
18
|
email: string;
|
18
19
|
firstName?: string;
|
@@ -25,12 +26,15 @@ declare class UserFromToken {
|
|
25
26
|
impersonatorUserId?: string;
|
26
27
|
constructor(userId: string, email: string, orgIdToOrgMemberInfo?: OrgIdToOrgMemberInfo, firstName?: string, lastName?: string, username?: string, legacyUserId?: string, impersonatorUserId?: string, properties?: {
|
27
28
|
[key: string]: unknown;
|
28
|
-
});
|
29
|
+
}, activeOrgId?: string);
|
30
|
+
getActiveOrg(): OrgMemberInfo | undefined;
|
31
|
+
getActiveOrgId(): string | undefined;
|
29
32
|
getOrg(orgId: string): OrgMemberInfo | undefined;
|
30
33
|
getOrgByName(orgName: string): OrgMemberInfo | undefined;
|
31
34
|
getOrgs(): OrgMemberInfo[];
|
32
35
|
isImpersonating(): boolean;
|
33
36
|
static fromJSON(json: string): UserFromToken;
|
37
|
+
static fromJwtPayload(payload: InternalUser): UserFromToken;
|
34
38
|
}
|
35
39
|
type OrgIdToOrgMemberInfo = {
|
36
40
|
[orgId: string]: OrgMemberInfo;
|
@@ -57,13 +61,41 @@ declare class OrgMemberInfo {
|
|
57
61
|
get inheritedRolesPlusCurrentRole(): string[];
|
58
62
|
get permissions(): string[];
|
59
63
|
}
|
64
|
+
type InternalOrgMemberInfo = {
|
65
|
+
org_id: string;
|
66
|
+
org_name: string;
|
67
|
+
org_metadata: {
|
68
|
+
[key: string]: any;
|
69
|
+
};
|
70
|
+
url_safe_org_name: string;
|
71
|
+
user_role: string;
|
72
|
+
inherited_user_roles_plus_current_role: string[];
|
73
|
+
user_permissions: string[];
|
74
|
+
};
|
75
|
+
type InternalUser = {
|
76
|
+
user_id: string;
|
77
|
+
org_member_info?: InternalOrgMemberInfo;
|
78
|
+
org_id_to_org_member_info?: {
|
79
|
+
[org_id: string]: InternalOrgMemberInfo;
|
80
|
+
};
|
81
|
+
email: string;
|
82
|
+
first_name?: string;
|
83
|
+
last_name?: string;
|
84
|
+
username?: string;
|
85
|
+
properties?: {
|
86
|
+
[key: string]: unknown;
|
87
|
+
};
|
88
|
+
legacy_user_id?: string;
|
89
|
+
impersonatorUserId?: string;
|
90
|
+
};
|
60
91
|
|
61
92
|
declare function getUserOrRedirect(): Promise<UserFromToken>;
|
62
93
|
declare function getUser(): Promise<UserFromToken | undefined>;
|
63
|
-
declare function getAccessToken():
|
94
|
+
declare function getAccessToken(): string | undefined;
|
64
95
|
declare function authMiddleware(req: NextRequest): Promise<Response>;
|
65
96
|
type RouteHandlerArgs = {
|
66
97
|
postLoginRedirectPathFn?: (req: NextRequest) => string;
|
98
|
+
getDefaultActiveOrgId?: (req: NextRequest, user: UserFromToken) => string | undefined;
|
67
99
|
};
|
68
100
|
declare function getRouteHandlers(args?: RouteHandlerArgs): {
|
69
101
|
getRouteHandler: (req: NextRequest, { params }: {
|