react-sso-provider v3.0.26
REACT SSO PROVIDER
Share local storage of your React application across domains
Installation
npm install react-sso-provider
Host App
To make your app a host. Import HostContextProvider
import { HostContextProvider } from "react-sso-provider";
Wrap your app with the provider
<HostContextProvider
guestDomains={[
{
origin: "https://<guest domain>",
allowedMethods: ["get", "set", "remove"],
},
]}
>
{children}
</HostContextProvider>
It takes guestDomains as props . This prop (guestDomains) is an array of domains you want to provide access to the localstorage of your Host aaplication.
Guest App
To make your app a guest. import GuestContextProvider
import { GuestContextProvider } from "react-sso-provider";
Wrap your app in GuestContextProvider
<GuestContextProvider hostDomain="http://<host domain>">
{children}
</GuestContextProvider>
Now , in the guest app you can use the guest context.
const {
getHostStorageVariable,
setHostStorageVariable,
removeHostStorageVariable,
} = useContext(GuestContext);
These function destructured from the guest context return Promise. So we need to await.
getHostStorageVariable=> this function fetches localstorage variable of host
setHostStorageVariable=> this function sets localstorage variable of host
setHostStorageVariable=> this function deletes localstorage variable of host