Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@propelauth/react

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@propelauth/react - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

203

dist/index.cjs.js

@@ -503,2 +503,122 @@ 'use strict';

function getOrgHelper(orgIdToOrgMemberInfo, selectOrgId, userSelectedOrgId) {
return {
getOrg(orgId) {
if (orgIdToOrgMemberInfo.hasOwnProperty(orgId)) {
return orgIdToOrgMemberInfo[orgId];
} else {
return undefined;
}
},
getOrgIds() {
return Object.keys(orgIdToOrgMemberInfo);
},
getOrgs() {
return Object.values(orgIdToOrgMemberInfo);
},
getSelectedOrg(inferDefault) {
// default for inferDefault is true
inferDefault = inferDefault === undefined ? true : inferDefault; // if the user has selected an org already, return it
if (userSelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(userSelectedOrgId)) {
return orgIdToOrgMemberInfo[userSelectedOrgId];
} else if (!inferDefault) {
return undefined;
} // otherwise, infer it from local storage
const previouslySelectedOrgId = loadOrgSelectionFromLocalStorage();
if (previouslySelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(previouslySelectedOrgId)) {
return orgIdToOrgMemberInfo[previouslySelectedOrgId];
} // if the user has never selected one before, select one deterministically by name
let alphabeticallyFirstOrgName = undefined;
let alphabeticallyFirstOrg = undefined;
for (let org of this.getOrgs()) {
if (!alphabeticallyFirstOrgName || org.orgName < alphabeticallyFirstOrgName) {
alphabeticallyFirstOrgName = org.orgName;
alphabeticallyFirstOrg = org;
}
}
return alphabeticallyFirstOrg;
},
selectOrg(orgId) {
selectOrgId(orgId);
saveOrgSelectionToLocalStorage(orgId);
},
getNotSelectedOrgs(inferDefault) {
const selectedOrg = this.getSelectedOrg(inferDefault);
if (selectedOrg) {
return this.getOrgs().filter(org => org.orgId !== selectedOrg.orgId);
} else {
return this.getOrgs();
}
}
};
}
const ORG_SELECTION_LOCAL_STORAGE_KEY = "__last_selected_org";
function saveOrgSelectionToLocalStorage(orgId) {
if (localStorage) {
localStorage.setItem(ORG_SELECTION_LOCAL_STORAGE_KEY, orgId);
}
}
function loadOrgSelectionFromLocalStorage() {
if (localStorage) {
return localStorage.getItem(ORG_SELECTION_LOCAL_STORAGE_KEY);
}
return null;
}
function useAuthInfo() {
const context = React.useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuthInfo must be used within an AuthProvider");
}
const {
loading,
authInfo,
selectOrgId,
userSelectedOrgId
} = context;
if (loading) {
return {
loading: true
};
} else if (authInfo && authInfo.accessToken) {
const orgHelper = getOrgHelper(authInfo.orgIdToOrgMemberInfo || {}, selectOrgId, userSelectedOrgId);
return {
loading: false,
isLoggedIn: true,
accessToken: authInfo.accessToken,
orgHelper: orgHelper,
user: authInfo.user
};
}
return {
loading: false,
isLoggedIn: false,
accessToken: null,
orgHelper: null,
user: null
};
}
function useLogoutFunction() {

@@ -896,84 +1016,2 @@ const context = React.useContext(AuthContext);

function getOrgHelper(orgIdToOrgMemberInfo, selectOrgId, userSelectedOrgId) {
return {
getOrg(orgId) {
if (orgIdToOrgMemberInfo.hasOwnProperty(orgId)) {
return orgIdToOrgMemberInfo[orgId];
} else {
return undefined;
}
},
getOrgIds() {
return Object.keys(orgIdToOrgMemberInfo);
},
getOrgs() {
return Object.values(orgIdToOrgMemberInfo);
},
getSelectedOrg(inferDefault) {
// default for inferDefault is true
inferDefault = inferDefault === undefined ? true : inferDefault; // if the user has selected an org already, return it
if (userSelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(userSelectedOrgId)) {
return orgIdToOrgMemberInfo[userSelectedOrgId];
} else if (!inferDefault) {
return undefined;
} // otherwise, infer it from local storage
const previouslySelectedOrgId = loadOrgSelectionFromLocalStorage();
if (previouslySelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(previouslySelectedOrgId)) {
return orgIdToOrgMemberInfo[previouslySelectedOrgId];
} // if the user has never selected one before, select one deterministically by name
let alphabeticallyFirstOrgName = undefined;
let alphabeticallyFirstOrg = undefined;
for (let org of this.getOrgs()) {
if (!alphabeticallyFirstOrgName || org.orgName < alphabeticallyFirstOrgName) {
alphabeticallyFirstOrgName = org.orgName;
alphabeticallyFirstOrg = org;
}
}
return alphabeticallyFirstOrg;
},
selectOrg(orgId) {
selectOrgId(orgId);
saveOrgSelectionToLocalStorage(orgId);
},
getNotSelectedOrgs(inferDefault) {
const selectedOrg = this.getSelectedOrg(inferDefault);
if (selectedOrg) {
return this.getOrgs().filter(org => org.orgId !== selectedOrg.orgId);
} else {
return this.getOrgs();
}
}
};
}
const ORG_SELECTION_LOCAL_STORAGE_KEY = "__last_selected_org";
function saveOrgSelectionToLocalStorage(orgId) {
if (localStorage) {
localStorage.setItem(ORG_SELECTION_LOCAL_STORAGE_KEY, orgId);
}
}
function loadOrgSelectionFromLocalStorage() {
if (localStorage) {
return localStorage.getItem(ORG_SELECTION_LOCAL_STORAGE_KEY);
}
return null;
}
function withAuthInfo(Component, args) {

@@ -1034,2 +1072,3 @@ const displayName = `withAuthInfo(${Component.displayName || Component.name || "Component"})`;

exports.RedirectToSignup = RedirectToSignup;
exports.useAuthInfo = useAuthInfo;
exports.useLogoutFunction = useLogoutFunction;

@@ -1036,0 +1075,0 @@ exports.useRedirectFunctions = useRedirectFunctions;

@@ -495,2 +495,122 @@ import React, { useReducer, useState, useMemo, useEffect, useCallback, useContext } from 'react';

function getOrgHelper(orgIdToOrgMemberInfo, selectOrgId, userSelectedOrgId) {
return {
getOrg(orgId) {
if (orgIdToOrgMemberInfo.hasOwnProperty(orgId)) {
return orgIdToOrgMemberInfo[orgId];
} else {
return undefined;
}
},
getOrgIds() {
return Object.keys(orgIdToOrgMemberInfo);
},
getOrgs() {
return Object.values(orgIdToOrgMemberInfo);
},
getSelectedOrg(inferDefault) {
// default for inferDefault is true
inferDefault = inferDefault === undefined ? true : inferDefault; // if the user has selected an org already, return it
if (userSelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(userSelectedOrgId)) {
return orgIdToOrgMemberInfo[userSelectedOrgId];
} else if (!inferDefault) {
return undefined;
} // otherwise, infer it from local storage
const previouslySelectedOrgId = loadOrgSelectionFromLocalStorage();
if (previouslySelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(previouslySelectedOrgId)) {
return orgIdToOrgMemberInfo[previouslySelectedOrgId];
} // if the user has never selected one before, select one deterministically by name
let alphabeticallyFirstOrgName = undefined;
let alphabeticallyFirstOrg = undefined;
for (let org of this.getOrgs()) {
if (!alphabeticallyFirstOrgName || org.orgName < alphabeticallyFirstOrgName) {
alphabeticallyFirstOrgName = org.orgName;
alphabeticallyFirstOrg = org;
}
}
return alphabeticallyFirstOrg;
},
selectOrg(orgId) {
selectOrgId(orgId);
saveOrgSelectionToLocalStorage(orgId);
},
getNotSelectedOrgs(inferDefault) {
const selectedOrg = this.getSelectedOrg(inferDefault);
if (selectedOrg) {
return this.getOrgs().filter(org => org.orgId !== selectedOrg.orgId);
} else {
return this.getOrgs();
}
}
};
}
const ORG_SELECTION_LOCAL_STORAGE_KEY = "__last_selected_org";
function saveOrgSelectionToLocalStorage(orgId) {
if (localStorage) {
localStorage.setItem(ORG_SELECTION_LOCAL_STORAGE_KEY, orgId);
}
}
function loadOrgSelectionFromLocalStorage() {
if (localStorage) {
return localStorage.getItem(ORG_SELECTION_LOCAL_STORAGE_KEY);
}
return null;
}
function useAuthInfo() {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuthInfo must be used within an AuthProvider");
}
const {
loading,
authInfo,
selectOrgId,
userSelectedOrgId
} = context;
if (loading) {
return {
loading: true
};
} else if (authInfo && authInfo.accessToken) {
const orgHelper = getOrgHelper(authInfo.orgIdToOrgMemberInfo || {}, selectOrgId, userSelectedOrgId);
return {
loading: false,
isLoggedIn: true,
accessToken: authInfo.accessToken,
orgHelper: orgHelper,
user: authInfo.user
};
}
return {
loading: false,
isLoggedIn: false,
accessToken: null,
orgHelper: null,
user: null
};
}
function useLogoutFunction() {

@@ -888,84 +1008,2 @@ const context = useContext(AuthContext);

function getOrgHelper(orgIdToOrgMemberInfo, selectOrgId, userSelectedOrgId) {
return {
getOrg(orgId) {
if (orgIdToOrgMemberInfo.hasOwnProperty(orgId)) {
return orgIdToOrgMemberInfo[orgId];
} else {
return undefined;
}
},
getOrgIds() {
return Object.keys(orgIdToOrgMemberInfo);
},
getOrgs() {
return Object.values(orgIdToOrgMemberInfo);
},
getSelectedOrg(inferDefault) {
// default for inferDefault is true
inferDefault = inferDefault === undefined ? true : inferDefault; // if the user has selected an org already, return it
if (userSelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(userSelectedOrgId)) {
return orgIdToOrgMemberInfo[userSelectedOrgId];
} else if (!inferDefault) {
return undefined;
} // otherwise, infer it from local storage
const previouslySelectedOrgId = loadOrgSelectionFromLocalStorage();
if (previouslySelectedOrgId && orgIdToOrgMemberInfo.hasOwnProperty(previouslySelectedOrgId)) {
return orgIdToOrgMemberInfo[previouslySelectedOrgId];
} // if the user has never selected one before, select one deterministically by name
let alphabeticallyFirstOrgName = undefined;
let alphabeticallyFirstOrg = undefined;
for (let org of this.getOrgs()) {
if (!alphabeticallyFirstOrgName || org.orgName < alphabeticallyFirstOrgName) {
alphabeticallyFirstOrgName = org.orgName;
alphabeticallyFirstOrg = org;
}
}
return alphabeticallyFirstOrg;
},
selectOrg(orgId) {
selectOrgId(orgId);
saveOrgSelectionToLocalStorage(orgId);
},
getNotSelectedOrgs(inferDefault) {
const selectedOrg = this.getSelectedOrg(inferDefault);
if (selectedOrg) {
return this.getOrgs().filter(org => org.orgId !== selectedOrg.orgId);
} else {
return this.getOrgs();
}
}
};
}
const ORG_SELECTION_LOCAL_STORAGE_KEY = "__last_selected_org";
function saveOrgSelectionToLocalStorage(orgId) {
if (localStorage) {
localStorage.setItem(ORG_SELECTION_LOCAL_STORAGE_KEY, orgId);
}
}
function loadOrgSelectionFromLocalStorage() {
if (localStorage) {
return localStorage.getItem(ORG_SELECTION_LOCAL_STORAGE_KEY);
}
return null;
}
function withAuthInfo(Component, args) {

@@ -1023,3 +1061,3 @@ const displayName = `withAuthInfo(${Component.displayName || Component.name || "Component"})`;

export { AuthProvider, RedirectToLogin, RedirectToSignup, UserRole, useLogoutFunction, useRedirectFunctions, withAuthInfo };
export { AuthProvider, RedirectToLogin, RedirectToSignup, UserRole, useAuthInfo, useLogoutFunction, useRedirectFunctions, withAuthInfo };
//# sourceMappingURL=index.esm.js.map

@@ -0,6 +1,7 @@

export { UserRole } from "@propelauth/javascript";
export type { OrgIdToOrgMemberInfo, OrgMemberInfo, User } from "@propelauth/javascript";
export { UserRole } from "@propelauth/javascript";
export { AuthProvider } from "./AuthContext";
export type { AuthProviderProps } from "./AuthContext";
export type { OrgHelper } from "./OrgHelper";
export { useAuthInfo } from "./useAuthInfo";
export { useLogoutFunction } from "./useLogoutFunction";

@@ -7,0 +8,0 @@ export { RedirectToLogin, RedirectToSignup, useRedirectFunctions } from "./useRedirectFunctions";

@@ -8,3 +8,3 @@ {

},
"version": "1.2.3",
"version": "1.2.4",
"license": "MIT",

@@ -11,0 +11,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc