hiko-social-login-react
Version:
HIKO Social Login react for Hydrogen integration
49 lines (36 loc) • 1.43 kB
Markdown
- [HIKO Social Login](https://apps.shopify.com/simple-social-login) is a Shopify social login app.
- The module provides a React component [SocialLoginWidget](https://github.com/jackcylin/hiko-social-login-react/blob/main/SocialLoginWidget.jsx) and sample codes to integrate with Hydrogen app.
```shell
$ npm i hiko-social-login-react --save
or
$ yarn add hiko-social-login-react
```
```js
const shop = "xxxx.myshopify.com";
const [customer, setCustomer] = useState(window.HIKO?.customer);
const handleCustomEvents = useCallback((event) => {
if (["login", "activate", "multipass"].includes(event.detail.action))
setCustomer(event.detail.customer);
}, []);
useEffect(() => {
document.addEventListener("hiko", handleCustomEvents);
return () => document.removeEventListener("hiko", handleCustomEvents);
}, []);
if (customer)
return (
<ul>
{Object.keys(customer).map((key) => (
<li key={key}>
{key}: {customer[key]}
</li>
))}
</ul>
);
return <SocialLoginWidget shop={shop} publicAccessToken={publicAccessToken}></SocialLoginWidget>;
```
- full sample [Demo.jsx](https://github.com/jackcylin/hiko-social-login-react/blob/main/src/Demo.tsx)
- Install [Headless](https://apps.shopify.com/headless) to generate publicAccessToken