@oxyhq/services 0.0.78 → 0.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"AccountSwitcherModal.d.ts","sourceRoot":"","sources":["../../../src/components/auth/AccountSwitcherModal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAyB/B,UAAU,yBAAyB;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,kGA0G/B,CAAC"}
1
+ {"version":3,"file":"AccountSwitcherModal.d.ts","sourceRoot":"","sources":["../../../src/components/auth/AccountSwitcherModal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA0B/B,UAAU,yBAAyB;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,kGAiH/B,CAAC"}
@@ -9,17 +9,25 @@ import { PiSignOutBold } from "react-icons/pi";
9
9
  import { AiOutlineClose } from "react-icons/ai";
10
10
  import { Avatar } from "../../features/profile";
11
11
  import getUserById from "../../hooks/getUserById";
12
+ import useCrossDomainStorage from "../../hooks/useCrossDomainStorage";
12
13
  import styles from "./styles/account-switcher-modal.module.css";
13
14
  export const AccountSwitcherModal = forwardRef((props, ref) => {
14
15
  const { onClose } = props;
15
16
  const { session } = useOxySession();
17
+ const { get, set } = useCrossDomainStorage();
16
18
  const [user, setUser] = useState(null);
17
19
  const [error, setError] = useState(null);
18
20
  useEffect(() => {
19
21
  const fetchUser = async () => {
20
22
  try {
21
- const fetchedUser = await getUserById(session?.user?.id);
22
- setUser(fetchedUser);
23
+ const clientKey = get("clientKey");
24
+ if (clientKey) {
25
+ const fetchedUser = await getUserById(clientKey);
26
+ setUser(fetchedUser);
27
+ }
28
+ else {
29
+ setError("Client key is missing");
30
+ }
23
31
  }
24
32
  catch (error) {
25
33
  if (error instanceof Error) {
@@ -33,12 +41,13 @@ export const AccountSwitcherModal = forwardRef((props, ref) => {
33
41
  if (session) {
34
42
  fetchUser();
35
43
  }
36
- }, [session]);
44
+ }, [session, get]);
37
45
  if (!session)
38
46
  return null;
39
47
  const handleBackdropClick = (e) => {
40
48
  e.stopPropagation();
41
49
  if (e.currentTarget === e.target) {
50
+ set("clientKey", "");
42
51
  onClose();
43
52
  }
44
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SignInButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SignInButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,eAAO,MAAM,YAAY,8BAItB;IACD,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,sBAgBA,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"SignInButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SignInButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,eAAO,MAAM,YAAY,8BAItB;IACD,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,sBAmBA,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,10 +1,13 @@
1
1
  import React from "react";
2
2
  import styles from "./styles/sign-in-button.module.css";
3
3
  import { OxyLogo } from "../assets/oxy-logo";
4
+ import useCrossDomainStorage from "../../hooks/useCrossDomainStorage";
4
5
  export const SignInButton = ({ icon = React.createElement(OxyLogo, null), text = "Sign in with Oxy", callback = typeof window !== "undefined" ? window.location.href : "", }) => {
6
+ const { set } = useCrossDomainStorage();
5
7
  const onClick = () => {
6
8
  if (typeof window !== "undefined") {
7
9
  const redirectUrl = `https://auth.oxy.so/?callback=${encodeURIComponent(callback)}`;
10
+ set("clientKey", ""); // Clear the clientKey before redirecting
8
11
  window.location.href = redirectUrl;
9
12
  }
10
13
  };
@@ -0,0 +1,6 @@
1
+ declare const useCrossDomainStorage: () => {
2
+ set: (key: string, value: string) => void;
3
+ get: (key: string) => string | null;
4
+ };
5
+ export default useCrossDomainStorage;
6
+ //# sourceMappingURL=useCrossDomainStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCrossDomainStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCrossDomainStorage.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,qBAAqB;eACP,MAAM,SAAS,MAAM;eAKrB,MAAM;CAmBzB,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { useEffect } from "react";
2
+ const useCrossDomainStorage = () => {
3
+ const set = (key, value) => {
4
+ localStorage.setItem(key, value);
5
+ window.postMessage({ key, value }, "*");
6
+ };
7
+ const get = (key) => {
8
+ return localStorage.getItem(key);
9
+ };
10
+ const handlePostMessage = (event) => {
11
+ if (event.origin !== window.location.origin) {
12
+ const { key, value } = event.data;
13
+ localStorage.setItem(key, value);
14
+ }
15
+ };
16
+ useEffect(() => {
17
+ window.addEventListener("message", handlePostMessage);
18
+ return () => {
19
+ window.removeEventListener("message", handlePostMessage);
20
+ };
21
+ }, []);
22
+ return { set, get };
23
+ };
24
+ export default useCrossDomainStorage;
@@ -1 +1 @@
1
- {"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM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;EAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { useEffect } from "react";
2
2
  import axios from "axios";
3
3
  import { create } from "zustand";
4
- import localforage from "localforage";
5
4
  import { OXY_AUTH_URL } from "../config";
5
+ import useCrossDomainStorage from "./useCrossDomainStorage";
6
6
  export const useSessionStore = create((set) => {
7
7
  let isFirstFetch = true;
8
8
  return {
@@ -20,11 +20,13 @@ export const useSessionStore = create((set) => {
20
20
  let clientKey = urlParams.get("clientKey");
21
21
  // If the session ID was not found in the URL parameters, get it from local storage
22
22
  if (!clientKey) {
23
- clientKey = await localforage.getItem("clientKey");
23
+ const { get } = useCrossDomainStorage();
24
+ clientKey = get("clientKey");
24
25
  }
25
26
  else {
26
27
  // If the session ID was found in the URL parameters, set it in local storage
27
- await localforage.setItem("clientKey", clientKey);
28
+ const { set } = useCrossDomainStorage();
29
+ set("clientKey", clientKey);
28
30
  }
29
31
  const response = await axios.get(OXY_AUTH_URL + "/api/session/" + clientKey);
30
32
  if (response.status !== 200) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/services",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "description": "",
5
5
  "homepage": "https://oxy.so/",
6
6
  "main": "./dist/index.js",