@propelauth/nextjs 0.0.123 → 0.0.125

Sign up to get free protection for your applications and to get access to all the features.
@@ -106,6 +106,10 @@ declare class UserFromToken {
106
106
  type OrgIdToOrgMemberInfo = {
107
107
  [orgId: string]: OrgMemberInfo;
108
108
  };
109
+ declare enum OrgRoleStructure {
110
+ SingleRole = "single_role_in_hierarchy",
111
+ MultiRole = "multi_role"
112
+ }
109
113
  declare class OrgMemberInfo {
110
114
  orgId: string;
111
115
  orgName: string;
@@ -113,18 +117,21 @@ declare class OrgMemberInfo {
113
117
  [key: string]: any;
114
118
  };
115
119
  urlSafeOrgName: string;
120
+ orgRoleStructure: OrgRoleStructure;
116
121
  userAssignedRole: string;
117
122
  userInheritedRolesPlusCurrentRole: string[];
118
123
  userPermissions: string[];
124
+ userAssignedAdditionalRoles: string[];
119
125
  constructor(orgId: string, orgName: string, orgMetadata: {
120
126
  [key: string]: any;
121
- }, urlSafeOrgName: string, userAssignedRole: string, userInheritedRolesPlusCurrentRole: string[], userPermissions: string[]);
127
+ }, urlSafeOrgName: string, userAssignedRole: string, userInheritedRolesPlusCurrentRole: string[], userPermissions: string[], orgRoleStructure: OrgRoleStructure, userAssignedAdditionalRoles: string[]);
122
128
  isRole(role: string): boolean;
123
129
  isAtLeastRole(role: string): boolean;
124
130
  hasPermission(permission: string): boolean;
125
131
  hasAllPermissions(permissions: string[]): boolean;
126
132
  static fromJSON(json: string): OrgMemberInfo;
127
133
  get assignedRole(): string;
134
+ get assignedRoles(): string[];
128
135
  get inheritedRolesPlusCurrentRole(): string[];
129
136
  get permissions(): string[];
130
137
  }
@@ -135,9 +142,11 @@ type InternalOrgMemberInfo = {
135
142
  [key: string]: any;
136
143
  };
137
144
  url_safe_org_name: string;
145
+ org_role_structure: OrgRoleStructure;
138
146
  user_role: string;
139
147
  inherited_user_roles_plus_current_role: string[];
140
148
  user_permissions: string[];
149
+ additional_roles: string[];
141
150
  };
142
151
  type InternalUser = {
143
152
  user_id: string;
@@ -206,21 +206,31 @@ var UserFromToken = class {
206
206
  }
207
207
  };
208
208
  var OrgMemberInfo = class {
209
- constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions) {
209
+ constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions, orgRoleStructure, userAssignedAdditionalRoles) {
210
210
  this.orgId = orgId;
211
211
  this.orgName = orgName;
212
212
  this.orgMetadata = orgMetadata;
213
213
  this.urlSafeOrgName = urlSafeOrgName;
214
+ this.orgRoleStructure = orgRoleStructure;
214
215
  this.userAssignedRole = userAssignedRole;
215
216
  this.userInheritedRolesPlusCurrentRole = userInheritedRolesPlusCurrentRole;
216
217
  this.userPermissions = userPermissions;
218
+ this.userAssignedAdditionalRoles = userAssignedAdditionalRoles;
217
219
  }
218
220
  // validation methods
219
221
  isRole(role) {
220
- return this.userAssignedRole === role;
222
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
223
+ return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role);
224
+ } else {
225
+ return this.userAssignedRole === role;
226
+ }
221
227
  }
222
228
  isAtLeastRole(role) {
223
- return this.userInheritedRolesPlusCurrentRole.includes(role);
229
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
230
+ return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role);
231
+ } else {
232
+ return this.userInheritedRolesPlusCurrentRole.includes(role);
233
+ }
224
234
  }
225
235
  hasPermission(permission) {
226
236
  return this.userPermissions.includes(permission);
@@ -237,15 +247,28 @@ var OrgMemberInfo = class {
237
247
  obj.urlSafeOrgName,
238
248
  obj.userAssignedRole,
239
249
  obj.userInheritedRolesPlusCurrentRole,
240
- obj.userPermissions
250
+ obj.userPermissions,
251
+ obj.orgRoleStructure,
252
+ obj.userAssignedAdditionalRoles
241
253
  );
242
254
  }
243
255
  // getters for the private fields
244
256
  get assignedRole() {
245
257
  return this.userAssignedRole;
246
258
  }
259
+ get assignedRoles() {
260
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
261
+ return this.userAssignedAdditionalRoles.concat(this.userAssignedRole);
262
+ } else {
263
+ return [this.userAssignedRole];
264
+ }
265
+ }
247
266
  get inheritedRolesPlusCurrentRole() {
248
- return this.userInheritedRolesPlusCurrentRole;
267
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
268
+ return this.userAssignedAdditionalRoles.concat(this.userAssignedRole);
269
+ } else {
270
+ return this.userInheritedRolesPlusCurrentRole;
271
+ }
249
272
  }
250
273
  get permissions() {
251
274
  return this.userPermissions;
@@ -266,7 +289,9 @@ function toOrgIdToOrgMemberInfo(snake_case) {
266
289
  snakeCaseValue.url_safe_org_name,
267
290
  snakeCaseValue.user_role,
268
291
  snakeCaseValue.inherited_user_roles_plus_current_role,
269
- snakeCaseValue.user_permissions
292
+ snakeCaseValue.user_permissions,
293
+ snakeCaseValue.org_role_structure,
294
+ snakeCaseValue.additional_roles
270
295
  );
271
296
  }
272
297
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/client/index.ts","../../src/loginMethod.ts","../../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 type {OrgIdToOrgMemberInfo} from \"../user\"\nexport {UserFromToken, OrgMemberInfo} from \"../user\"\nexport {AuthProvider} from \"./AuthProvider\"\nexport type {AuthProviderProps, RedirectToLoginOptions, RedirectToSignupOptions} from \"./AuthProvider\"\nexport {useUser, User} from \"./useUser\"\nexport type {UseUser, UseUserLoading, UseUserLoggedIn, UseUserNotLoggedIn} from \"./useUser\"\nexport {useHostedPageUrls} from \"./useHostedPageUrls\"\nexport {useLogoutFunction} from \"./useLogoutFunction\"\nexport {useRedirectFunctions, RedirectToLogin, RedirectToSignup} from \"./useRedirectFunctions\"\nexport type {RedirectProps} from \"./useRedirectFunctions\"\nexport {useRefreshAuth} from \"./useRefreshAuth\"","export enum SocialLoginProvider {\n Google = 'Google',\n GitHub = 'GitHub',\n Microsoft = 'Microsoft',\n Slack = 'Slack',\n LinkedIn = 'LinkedIn',\n Salesforce = 'Salesforce',\n Xero = 'Xero',\n QuickBooksOnline = 'QuickBooks Online',\n}\n\nexport enum SamlLoginProvider {\n Google = 'Google',\n Rippling = 'Rippling',\n OneLogin = 'OneLogin',\n JumpCloud = 'JumpCloud',\n Okta = 'Okta',\n Azure = 'Azure',\n Duo = 'Duo',\n Generic = 'Generic',\n}\n\ntype InternalPasswordLoginMethod = {\n login_method: 'password'\n}\n\ntype InternalMagicLinkLoginMethod = {\n login_method: 'magic_link'\n}\n\ntype InternalSocialSsoLoginMethod = {\n login_method: 'social_sso'\n provider: SocialLoginProvider\n}\n\ntype InternalEmailConfirmationLinkLoginMethod = {\n login_method: 'email_confirmation_link'\n}\n\ntype InternalSamlSsoLoginMethod = {\n login_method: 'saml_sso'\n provider: SamlLoginProvider\n org_id: string\n}\n\ntype InternalImpersonationLoginMethod = {\n login_method: 'impersonation'\n}\n\ntype InternalGeneratedFromBackendApiLoginMethod = {\n login_method: 'generated_from_backend_api'\n}\n\ntype InternalUnknownLoginMethod = {\n login_method: 'unknown'\n}\n\nexport type InternalLoginMethod =\n | InternalPasswordLoginMethod\n | InternalMagicLinkLoginMethod\n | InternalSocialSsoLoginMethod\n | InternalEmailConfirmationLinkLoginMethod\n | InternalSamlSsoLoginMethod\n | InternalImpersonationLoginMethod\n | InternalGeneratedFromBackendApiLoginMethod\n | InternalUnknownLoginMethod\n\ntype PasswordLoginMethod = {\n loginMethod: 'password'\n}\n\ntype MagicLinkLoginMethod = {\n loginMethod: 'magic_link'\n}\n\ntype SocialSsoLoginMethod = {\n loginMethod: 'social_sso'\n provider: SocialLoginProvider\n}\n\ntype EmailConfirmationLinkLoginMethod = {\n loginMethod: 'email_confirmation_link'\n}\n\ntype SamlSsoLoginMethod = {\n loginMethod: 'saml_sso'\n provider: SamlLoginProvider\n orgId: string\n}\n\ntype ImpersonationLoginMethod = {\n loginMethod: 'impersonation'\n}\n\ntype GeneratedFromBackendApiLoginMethod = {\n loginMethod: 'generated_from_backend_api'\n}\n\ntype UnknownLoginMethod = {\n loginMethod: 'unknown'\n}\n\nexport type LoginMethod =\n | PasswordLoginMethod\n | MagicLinkLoginMethod\n | SocialSsoLoginMethod\n | EmailConfirmationLinkLoginMethod\n | SamlSsoLoginMethod\n | ImpersonationLoginMethod\n | GeneratedFromBackendApiLoginMethod\n | UnknownLoginMethod\n\nexport function toLoginMethod(snake_case?: InternalLoginMethod): LoginMethod {\n if (!snake_case) {\n return { loginMethod: 'unknown' }\n }\n\n switch (snake_case.login_method) {\n case 'password':\n return { loginMethod: 'password' }\n case 'magic_link':\n return { loginMethod: 'magic_link' }\n case 'social_sso':\n return { loginMethod: 'social_sso', provider: snake_case.provider }\n case 'email_confirmation_link':\n return { loginMethod: 'email_confirmation_link' }\n case 'saml_sso':\n return { loginMethod: 'saml_sso', provider: snake_case.provider, orgId: snake_case.org_id }\n case 'impersonation':\n return { loginMethod: 'impersonation' }\n case 'generated_from_backend_api':\n return { loginMethod: 'generated_from_backend_api' }\n default:\n return { loginMethod: 'unknown' }\n }\n}\n","import { InternalLoginMethod, LoginMethod, toLoginMethod } from './loginMethod'\n\nexport 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 public loginMethod?: LoginMethod\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 loginMethod?: LoginMethod\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 this.loginMethod = loginMethod\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 obj.activeOrgId,\n obj.loginMethod\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 const loginMethod = toLoginMethod(payload.login_method)\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 loginMethod\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}\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 login_method?: InternalLoginMethod\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 userSignupQueryParameters?: Record<string, string>\n}\nexport interface RedirectToLoginOptions {\n postLoginRedirectPath?: string\n userSignupQueryParameters?: Record<string, string>\n}\nexport interface RedirectOptions {\n redirectBackToUrl?: 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: (opts?: RedirectOptions) => void\n redirectToOrgPage: (orgId?: string, opts?: RedirectOptions) => void\n redirectToCreateOrgPage: (opts?: RedirectOptions) => void\n redirectToSetupSAMLPage: (orgId: string, opts?: RedirectOptions) => void\n\n getSignupPageUrl(opts?: RedirectToSignupOptions): string\n getLoginPageUrl(opts?: RedirectToLoginOptions): string\n getAccountPageUrl(opts?: RedirectOptions): string\n getOrgPageUrl(orgId?: string, opts?: RedirectOptions): string\n getCreateOrgPageUrl(opts?: RedirectOptions): string\n getSetupSAMLPageUrl(orgId: string, opts?: RedirectOptions): 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 && !action.error) {\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 let retryTimer: NodeJS.Timeout | undefined = undefined\n\n function clearAndSetRetryTimer() {\n if (retryTimer) {\n clearTimeout(retryTimer)\n }\n retryTimer = setTimeout(refreshToken, 30 * 1000)\n }\n\n async function refreshToken() {\n const action = await apiGetUserInfo()\n if (didCancel) {\n return\n }\n if (!action.error) {\n dispatch(action)\n } else if (action.error === 'unexpected') {\n clearAndSetRetryTimer()\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 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 (retryTimer) {\n clearTimeout(retryTimer)\n }\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 (opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/account`, opts?.redirectBackToUrl)\n },\n [props.authUrl]\n )\n const getOrgPageUrl = useCallback(\n (orgId?: string, opts?: RedirectOptions) => {\n if (orgId) {\n return addReturnToPath(`${props.authUrl}/org?id=${orgId}`, opts?.redirectBackToUrl)\n } else {\n return addReturnToPath(`${props.authUrl}/org`, opts?.redirectBackToUrl)\n }\n },\n [props.authUrl]\n )\n const getCreateOrgPageUrl = useCallback(\n (opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/create_org`, opts?.redirectBackToUrl)\n },\n [props.authUrl]\n )\n\n const getSetupSAMLPageUrl = useCallback(\n (orgId: string, opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/saml?id=${orgId}`, opts?.redirectBackToUrl)\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 = (opts?: RedirectOptions) => redirectTo(getAccountPageUrl(opts))\n const redirectToOrgPage = (orgId?: string, opts?: RedirectOptions) => redirectTo(getOrgPageUrl(orgId, opts))\n const redirectToCreateOrgPage = (opts?: RedirectOptions) => redirectTo(getCreateOrgPageUrl(opts))\n const redirectToSetupSAMLPage = (orgId: string, opts?: RedirectOptions) =>\n redirectTo(getSetupSAMLPageUrl(orgId, opts))\n\n const refreshAuthInfo = useCallback(async () => {\n const action = await apiGetUserInfo()\n if (action.error) {\n throw new Error('Failed to refresh token')\n } else {\n dispatch(action)\n return action.user\n }\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 error: undefined\n user: User\n accessToken: string\n }\n | {\n error: undefined\n user: undefined\n accessToken: undefined\n }\n | {\n error: 'unexpected'\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, error: undefined }\n } else if (userInfoResponse.status === 401) {\n return { user: undefined, accessToken: undefined, error: undefined }\n } else {\n console.info('Failed to refresh token', userInfoResponse)\n return { error: 'unexpected' }\n }\n } catch (e) {\n console.info('Failed to refresh token', e)\n return { error: 'unexpected' }\n }\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\nconst encodeBase64 = (str: string) => {\n const encode = window ? window.btoa : btoa\n return encode(str)\n}\n\nconst addReturnToPath = (url: string, returnToPath?: string) => {\n if (!returnToPath) {\n return url\n }\n\n let qs = new URLSearchParams()\n qs.set('rt', encodeBase64(returnToPath))\n if (url.includes('?')) {\n return `${url}&${qs.toString()}`\n } else {\n return `${url}?${qs.toString()}`\n }\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 } else if (a === null || b === null) {\n return a === b\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}\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 redirectToSetupSAMLPage,\n } = context\n return {\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n redirectToSetupSAMLPage,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgHO,SAAS,cAAc,YAA+C;AACzE,MAAI,CAAC,YAAY;AACb,WAAO,EAAE,aAAa,UAAU;AAAA,EACpC;AAEA,UAAQ,WAAW,cAAc;AAAA,IAC7B,KAAK;AACD,aAAO,EAAE,aAAa,WAAW;AAAA,IACrC,KAAK;AACD,aAAO,EAAE,aAAa,aAAa;AAAA,IACvC,KAAK;AACD,a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qBAAqB;AAEtD,+BAAU,MAAM;AACZ,yBAAqB;AAAA,EACzB,GAAG,CAAC,CAAC;AAEL,SAAO,8BAAAC,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AACvB;AAEO,SAAS,gBAAgB,EAAE,SAAS,GAAkB;AACzD,QAAM,EAAE,oBAAoB,IAAI,qBAAqB;AACrD,+BAAU,MAAM;AACZ,wBAAoB;AAAA,EACxB,GAAG,CAAC,CAAC;AACL,SAAO,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AACvB;;;AC9CA,IAAAC,gBAA2B;AAGpB,SAAS,iBAAiB;AAC7B,QAAM,cAAU,0BAAW,WAAW;AACtC,MAAI,YAAY,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACxE;AACA,QAAM,EAAE,gBAAgB,IAAI;AAC5B,SAAO;AACX;","names":["import_react","React","refreshAuthInfo","import_react","import_react","import_react","React","import_react"]}
1
+ {"version":3,"sources":["../../src/client/index.ts","../../src/loginMethod.ts","../../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 type {OrgIdToOrgMemberInfo} from \"../user\"\nexport {UserFromToken, OrgMemberInfo} from \"../user\"\nexport {AuthProvider} from \"./AuthProvider\"\nexport type {AuthProviderProps, RedirectToLoginOptions, RedirectToSignupOptions} from \"./AuthProvider\"\nexport {useUser, User} from \"./useUser\"\nexport type {UseUser, UseUserLoading, UseUserLoggedIn, UseUserNotLoggedIn} from \"./useUser\"\nexport {useHostedPageUrls} from \"./useHostedPageUrls\"\nexport {useLogoutFunction} from \"./useLogoutFunction\"\nexport {useRedirectFunctions, RedirectToLogin, RedirectToSignup} from \"./useRedirectFunctions\"\nexport type {RedirectProps} from \"./useRedirectFunctions\"\nexport {useRefreshAuth} from \"./useRefreshAuth\"","export enum SocialLoginProvider {\n Google = 'Google',\n GitHub = 'GitHub',\n Microsoft = 'Microsoft',\n Slack = 'Slack',\n LinkedIn = 'LinkedIn',\n Salesforce = 'Salesforce',\n Xero = 'Xero',\n QuickBooksOnline = 'QuickBooks Online',\n}\n\nexport enum SamlLoginProvider {\n Google = 'Google',\n Rippling = 'Rippling',\n OneLogin = 'OneLogin',\n JumpCloud = 'JumpCloud',\n Okta = 'Okta',\n Azure = 'Azure',\n Duo = 'Duo',\n Generic = 'Generic',\n}\n\ntype InternalPasswordLoginMethod = {\n login_method: 'password'\n}\n\ntype InternalMagicLinkLoginMethod = {\n login_method: 'magic_link'\n}\n\ntype InternalSocialSsoLoginMethod = {\n login_method: 'social_sso'\n provider: SocialLoginProvider\n}\n\ntype InternalEmailConfirmationLinkLoginMethod = {\n login_method: 'email_confirmation_link'\n}\n\ntype InternalSamlSsoLoginMethod = {\n login_method: 'saml_sso'\n provider: SamlLoginProvider\n org_id: string\n}\n\ntype InternalImpersonationLoginMethod = {\n login_method: 'impersonation'\n}\n\ntype InternalGeneratedFromBackendApiLoginMethod = {\n login_method: 'generated_from_backend_api'\n}\n\ntype InternalUnknownLoginMethod = {\n login_method: 'unknown'\n}\n\nexport type InternalLoginMethod =\n | InternalPasswordLoginMethod\n | InternalMagicLinkLoginMethod\n | InternalSocialSsoLoginMethod\n | InternalEmailConfirmationLinkLoginMethod\n | InternalSamlSsoLoginMethod\n | InternalImpersonationLoginMethod\n | InternalGeneratedFromBackendApiLoginMethod\n | InternalUnknownLoginMethod\n\ntype PasswordLoginMethod = {\n loginMethod: 'password'\n}\n\ntype MagicLinkLoginMethod = {\n loginMethod: 'magic_link'\n}\n\ntype SocialSsoLoginMethod = {\n loginMethod: 'social_sso'\n provider: SocialLoginProvider\n}\n\ntype EmailConfirmationLinkLoginMethod = {\n loginMethod: 'email_confirmation_link'\n}\n\ntype SamlSsoLoginMethod = {\n loginMethod: 'saml_sso'\n provider: SamlLoginProvider\n orgId: string\n}\n\ntype ImpersonationLoginMethod = {\n loginMethod: 'impersonation'\n}\n\ntype GeneratedFromBackendApiLoginMethod = {\n loginMethod: 'generated_from_backend_api'\n}\n\ntype UnknownLoginMethod = {\n loginMethod: 'unknown'\n}\n\nexport type LoginMethod =\n | PasswordLoginMethod\n | MagicLinkLoginMethod\n | SocialSsoLoginMethod\n | EmailConfirmationLinkLoginMethod\n | SamlSsoLoginMethod\n | ImpersonationLoginMethod\n | GeneratedFromBackendApiLoginMethod\n | UnknownLoginMethod\n\nexport function toLoginMethod(snake_case?: InternalLoginMethod): LoginMethod {\n if (!snake_case) {\n return { loginMethod: 'unknown' }\n }\n\n switch (snake_case.login_method) {\n case 'password':\n return { loginMethod: 'password' }\n case 'magic_link':\n return { loginMethod: 'magic_link' }\n case 'social_sso':\n return { loginMethod: 'social_sso', provider: snake_case.provider }\n case 'email_confirmation_link':\n return { loginMethod: 'email_confirmation_link' }\n case 'saml_sso':\n return { loginMethod: 'saml_sso', provider: snake_case.provider, orgId: snake_case.org_id }\n case 'impersonation':\n return { loginMethod: 'impersonation' }\n case 'generated_from_backend_api':\n return { loginMethod: 'generated_from_backend_api' }\n default:\n return { loginMethod: 'unknown' }\n }\n}\n","import { InternalLoginMethod, LoginMethod, toLoginMethod } from './loginMethod'\n\nexport 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 public loginMethod?: LoginMethod\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 loginMethod?: LoginMethod\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 this.loginMethod = loginMethod\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 obj.activeOrgId,\n obj.loginMethod\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 const loginMethod = toLoginMethod(payload.login_method)\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 loginMethod\n )\n }\n}\n\nexport type OrgIdToOrgMemberInfo = {\n [orgId: string]: OrgMemberInfo\n}\n\nexport enum OrgRoleStructure {\n SingleRole = \"single_role_in_hierarchy\",\n MultiRole = \"multi_role\",\n}\n\nexport class OrgMemberInfo {\n public orgId: string\n public orgName: string\n public orgMetadata: { [key: string]: any }\n public urlSafeOrgName: string\n public orgRoleStructure: OrgRoleStructure\n\n public userAssignedRole: string\n public userInheritedRolesPlusCurrentRole: string[]\n public userPermissions: string[]\n public userAssignedAdditionalRoles: 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 orgRoleStructure: OrgRoleStructure,\n userAssignedAdditionalRoles: string[]\n ) {\n this.orgId = orgId\n this.orgName = orgName\n this.orgMetadata = orgMetadata\n this.urlSafeOrgName = urlSafeOrgName\n this.orgRoleStructure = orgRoleStructure\n\n this.userAssignedRole = userAssignedRole\n this.userInheritedRolesPlusCurrentRole = userInheritedRolesPlusCurrentRole\n this.userPermissions = userPermissions\n this.userAssignedAdditionalRoles = userAssignedAdditionalRoles\n }\n\n // validation methods\n\n public isRole(role: string): boolean {\n if (this.orgRoleStructure === OrgRoleStructure.MultiRole) {\n return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role)\n } else {\n return this.userAssignedRole === role\n }\n }\n\n public isAtLeastRole(role: string): boolean {\n if (this.orgRoleStructure === OrgRoleStructure.MultiRole) {\n return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role)\n } else {\n return this.userInheritedRolesPlusCurrentRole.includes(role)\n }\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 obj.orgRoleStructure,\n obj.userAssignedAdditionalRoles\n )\n }\n\n // getters for the private fields\n\n get assignedRole(): string {\n return this.userAssignedRole\n }\n\n get assignedRoles(): string[] {\n if (this.orgRoleStructure === OrgRoleStructure.MultiRole) {\n return this.userAssignedAdditionalRoles.concat(this.userAssignedRole)\n } else {\n return [this.userAssignedRole]\n }\n }\n\n get inheritedRolesPlusCurrentRole(): string[] {\n if (this.orgRoleStructure === OrgRoleStructure.MultiRole) {\n return this.userAssignedAdditionalRoles.concat(this.userAssignedRole)\n } else {\n return this.userInheritedRolesPlusCurrentRole\n }\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 org_role_structure: OrgRoleStructure\n user_role: string\n inherited_user_roles_plus_current_role: string[]\n user_permissions: string[]\n additional_roles: string[]\n}\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 login_method?: InternalLoginMethod\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 snakeCaseValue.org_role_structure,\n snakeCaseValue.additional_roles\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 userSignupQueryParameters?: Record<string, string>\n}\nexport interface RedirectToLoginOptions {\n postLoginRedirectPath?: string\n userSignupQueryParameters?: Record<string, string>\n}\nexport interface RedirectOptions {\n redirectBackToUrl?: 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: (opts?: RedirectOptions) => void\n redirectToOrgPage: (orgId?: string, opts?: RedirectOptions) => void\n redirectToCreateOrgPage: (opts?: RedirectOptions) => void\n redirectToSetupSAMLPage: (orgId: string, opts?: RedirectOptions) => void\n\n getSignupPageUrl(opts?: RedirectToSignupOptions): string\n getLoginPageUrl(opts?: RedirectToLoginOptions): string\n getAccountPageUrl(opts?: RedirectOptions): string\n getOrgPageUrl(orgId?: string, opts?: RedirectOptions): string\n getCreateOrgPageUrl(opts?: RedirectOptions): string\n getSetupSAMLPageUrl(orgId: string, opts?: RedirectOptions): 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 && !action.error) {\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 let retryTimer: NodeJS.Timeout | undefined = undefined\n\n function clearAndSetRetryTimer() {\n if (retryTimer) {\n clearTimeout(retryTimer)\n }\n retryTimer = setTimeout(refreshToken, 30 * 1000)\n }\n\n async function refreshToken() {\n const action = await apiGetUserInfo()\n if (didCancel) {\n return\n }\n if (!action.error) {\n dispatch(action)\n } else if (action.error === 'unexpected') {\n clearAndSetRetryTimer()\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 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 (retryTimer) {\n clearTimeout(retryTimer)\n }\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 (opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/account`, opts?.redirectBackToUrl)\n },\n [props.authUrl]\n )\n const getOrgPageUrl = useCallback(\n (orgId?: string, opts?: RedirectOptions) => {\n if (orgId) {\n return addReturnToPath(`${props.authUrl}/org?id=${orgId}`, opts?.redirectBackToUrl)\n } else {\n return addReturnToPath(`${props.authUrl}/org`, opts?.redirectBackToUrl)\n }\n },\n [props.authUrl]\n )\n const getCreateOrgPageUrl = useCallback(\n (opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/create_org`, opts?.redirectBackToUrl)\n },\n [props.authUrl]\n )\n\n const getSetupSAMLPageUrl = useCallback(\n (orgId: string, opts?: RedirectOptions) => {\n return addReturnToPath(`${props.authUrl}/saml?id=${orgId}`, opts?.redirectBackToUrl)\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 = (opts?: RedirectOptions) => redirectTo(getAccountPageUrl(opts))\n const redirectToOrgPage = (orgId?: string, opts?: RedirectOptions) => redirectTo(getOrgPageUrl(orgId, opts))\n const redirectToCreateOrgPage = (opts?: RedirectOptions) => redirectTo(getCreateOrgPageUrl(opts))\n const redirectToSetupSAMLPage = (orgId: string, opts?: RedirectOptions) =>\n redirectTo(getSetupSAMLPageUrl(orgId, opts))\n\n const refreshAuthInfo = useCallback(async () => {\n const action = await apiGetUserInfo()\n if (action.error) {\n throw new Error('Failed to refresh token')\n } else {\n dispatch(action)\n return action.user\n }\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 error: undefined\n user: User\n accessToken: string\n }\n | {\n error: undefined\n user: undefined\n accessToken: undefined\n }\n | {\n error: 'unexpected'\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, error: undefined }\n } else if (userInfoResponse.status === 401) {\n return { user: undefined, accessToken: undefined, error: undefined }\n } else {\n console.info('Failed to refresh token', userInfoResponse)\n return { error: 'unexpected' }\n }\n } catch (e) {\n console.info('Failed to refresh token', e)\n return { error: 'unexpected' }\n }\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\nconst encodeBase64 = (str: string) => {\n const encode = window ? window.btoa : btoa\n return encode(str)\n}\n\nconst addReturnToPath = (url: string, returnToPath?: string) => {\n if (!returnToPath) {\n return url\n }\n\n let qs = new URLSearchParams()\n qs.set('rt', encodeBase64(returnToPath))\n if (url.includes('?')) {\n return `${url}&${qs.toString()}`\n } else {\n return `${url}?${qs.toString()}`\n }\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 } else if (a === null || b === null) {\n return a === b\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}\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 redirectToSetupSAMLPage,\n } = context\n return {\n redirectToSignupPage,\n redirectToLoginPage,\n redirectToAccountPage,\n redirectToOrgPage,\n redirectToCreateOrgPage,\n redirectToSetupSAMLPage,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgHO,SAAS,cAAc,YAA+C;AACzE,MAAI,CAAC,YAAY;AACb,WAAO,EAAE,aAAa,UAAU;AAAA,EACpC;AAEA,UAAQ,WAAW,cAAc;AAAA,IAC7B,KAAK;AACD,aAAO,EAAE,aAAa,WAAW;AAAA,IACrC,KAAK;AACD,aAAO,EAAE,aAAa,aAAa;AAAA,IACvC,KAAK;AACD,aAAO,EAAE,aAAa,cAAc,UAAU,WAAW,SAAS;AAAA,IACtE,KAAK;AACD,aAAO,EAAE,aAAa,0BAA0B;AAAA,IACpD,KAAK;AACD,aAAO,EAAE,aAAa,YAAY,UAAU,WAAW,UAAU,OAAO,WAAW,OAAO;AAAA,IAC9F,KAAK;AACD,aAAO,EAAE,aAAa,gBAAgB;AAAA,IAC1C,KAAK;AACD,aAAO,EAAE,aAAa,6BAA6B;AAAA,IACvD;AACI,aAAO,EAAE,aAAa,UAAU;AAAA,EACxC;AACJ;;;ACrIO,IAAM,gBAAN,MAAoB;AAAA,EAmBvB,YACI,QACA,OACA,sBACA,WACA,UACA,UACA,cACA,oBACA,YACA,aACA,aACF;AACE,SAAK,SAAS;AAEd,SAAK,cAAc;AACnB,SAAK,uBAAuB;AAE5B,SAAK,QAAQ;AACb,SAAK,YAAY;AACjB,SAA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AAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;AAMO,SAAS,iBAAiB,EAAE,SAAS,GAAkB;AAC1D,QAAM,EAAE,qBAAqB,IAAI,qBAAqB;AAEtD,+BAAU,MAAM;AACZ,yBAAqB;AAAA,EACzB,GAAG,CAAC,CAAC;AAEL,SAAO,8BAAAC,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AACvB;AAEO,SAAS,gBAAgB,EAAE,SAAS,GAAkB;AACzD,QAAM,EAAE,oBAAoB,IAAI,qBAAqB;AACrD,+BAAU,MAAM;AACZ,wBAAoB;AAAA,EACxB,GAAG,CAAC,CAAC;AACL,SAAO,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AACvB;;;AC9CA,IAAAC,gBAA2B;AAGpB,SAAS,iBAAiB;AAC7B,QAAM,cAAU,0BAAW,WAAW;AACtC,MAAI,YAAY,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACxE;AACA,QAAM,EAAE,gBAAgB,IAAI;AAC5B,SAAO;AACX;","names":["import_react","React","refreshAuthInfo","import_react","import_react","import_react","React","import_react"]}
@@ -163,21 +163,31 @@ var UserFromToken = class {
163
163
  }
164
164
  };
165
165
  var OrgMemberInfo = class {
166
- constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions) {
166
+ constructor(orgId, orgName, orgMetadata, urlSafeOrgName, userAssignedRole, userInheritedRolesPlusCurrentRole, userPermissions, orgRoleStructure, userAssignedAdditionalRoles) {
167
167
  this.orgId = orgId;
168
168
  this.orgName = orgName;
169
169
  this.orgMetadata = orgMetadata;
170
170
  this.urlSafeOrgName = urlSafeOrgName;
171
+ this.orgRoleStructure = orgRoleStructure;
171
172
  this.userAssignedRole = userAssignedRole;
172
173
  this.userInheritedRolesPlusCurrentRole = userInheritedRolesPlusCurrentRole;
173
174
  this.userPermissions = userPermissions;
175
+ this.userAssignedAdditionalRoles = userAssignedAdditionalRoles;
174
176
  }
175
177
  // validation methods
176
178
  isRole(role) {
177
- return this.userAssignedRole === role;
179
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
180
+ return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role);
181
+ } else {
182
+ return this.userAssignedRole === role;
183
+ }
178
184
  }
179
185
  isAtLeastRole(role) {
180
- return this.userInheritedRolesPlusCurrentRole.includes(role);
186
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
187
+ return this.userAssignedRole === role || this.userAssignedAdditionalRoles.includes(role);
188
+ } else {
189
+ return this.userInheritedRolesPlusCurrentRole.includes(role);
190
+ }
181
191
  }
182
192
  hasPermission(permission) {
183
193
  return this.userPermissions.includes(permission);
@@ -194,15 +204,28 @@ var OrgMemberInfo = class {
194
204
  obj.urlSafeOrgName,
195
205
  obj.userAssignedRole,
196
206
  obj.userInheritedRolesPlusCurrentRole,
197
- obj.userPermissions
207
+ obj.userPermissions,
208
+ obj.orgRoleStructure,
209
+ obj.userAssignedAdditionalRoles
198
210
  );
199
211
  }
200
212
  // getters for the private fields
201
213
  get assignedRole() {
202
214
  return this.userAssignedRole;
203
215
  }
216
+ get assignedRoles() {
217
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
218
+ return this.userAssignedAdditionalRoles.concat(this.userAssignedRole);
219
+ } else {
220
+ return [this.userAssignedRole];
221
+ }
222
+ }
204
223
  get inheritedRolesPlusCurrentRole() {
205
- return this.userInheritedRolesPlusCurrentRole;
224
+ if (this.orgRoleStructure === "multi_role" /* MultiRole */) {
225
+ return this.userAssignedAdditionalRoles.concat(this.userAssignedRole);
226
+ } else {
227
+ return this.userInheritedRolesPlusCurrentRole;
228
+ }
206
229
  }
207
230
  get permissions() {
208
231
  return this.userPermissions;
@@ -223,7 +246,9 @@ function toOrgIdToOrgMemberInfo(snake_case) {
223
246
  snakeCaseValue.url_safe_org_name,
224
247
  snakeCaseValue.user_role,
225
248
  snakeCaseValue.inherited_user_roles_plus_current_role,
226
- snakeCaseValue.user_permissions
249
+ snakeCaseValue.user_permissions,
250
+ snakeCaseValue.org_role_structure,
251
+ snakeCaseValue.additional_roles
227
252
  );
228
253
  }
229
254
  }