@oxyhq/services 0.0.79 → 0.0.80
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.
- package/dist/components/auth/AccountSwitcherModal.d.ts.map +1 -1
- package/dist/components/auth/AccountSwitcherModal.js +3 -12
- package/dist/components/auth/SignInButton.d.ts.map +1 -1
- package/dist/components/auth/SignInButton.js +0 -3
- package/dist/hooks/getClientKey.d.ts +2 -0
- package/dist/hooks/getClientKey.d.ts.map +1 -0
- package/dist/hooks/getClientKey.js +19 -0
- package/dist/hooks/useOxySession.d.ts.map +1 -1
- package/dist/hooks/useOxySession.js +3 -14
- package/package.json +1 -1
|
@@ -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;
|
|
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"}
|
|
@@ -9,25 +9,17 @@ 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";
|
|
13
12
|
import styles from "./styles/account-switcher-modal.module.css";
|
|
14
13
|
export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
15
14
|
const { onClose } = props;
|
|
16
15
|
const { session } = useOxySession();
|
|
17
|
-
const { get, set } = useCrossDomainStorage();
|
|
18
16
|
const [user, setUser] = useState(null);
|
|
19
17
|
const [error, setError] = useState(null);
|
|
20
18
|
useEffect(() => {
|
|
21
19
|
const fetchUser = async () => {
|
|
22
20
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const fetchedUser = await getUserById(clientKey);
|
|
26
|
-
setUser(fetchedUser);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
setError("Client key is missing");
|
|
30
|
-
}
|
|
21
|
+
const fetchedUser = await getUserById(session?.user?.id);
|
|
22
|
+
setUser(fetchedUser);
|
|
31
23
|
}
|
|
32
24
|
catch (error) {
|
|
33
25
|
if (error instanceof Error) {
|
|
@@ -41,13 +33,12 @@ export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
|
41
33
|
if (session) {
|
|
42
34
|
fetchUser();
|
|
43
35
|
}
|
|
44
|
-
}, [session
|
|
36
|
+
}, [session]);
|
|
45
37
|
if (!session)
|
|
46
38
|
return null;
|
|
47
39
|
const handleBackdropClick = (e) => {
|
|
48
40
|
e.stopPropagation();
|
|
49
41
|
if (e.currentTarget === e.target) {
|
|
50
|
-
set("clientKey", "");
|
|
51
42
|
onClose();
|
|
52
43
|
}
|
|
53
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignInButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SignInButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
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,13 +1,10 @@
|
|
|
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";
|
|
5
4
|
export const SignInButton = ({ icon = React.createElement(OxyLogo, null), text = "Sign in with Oxy", callback = typeof window !== "undefined" ? window.location.href : "", }) => {
|
|
6
|
-
const { set } = useCrossDomainStorage();
|
|
7
5
|
const onClick = () => {
|
|
8
6
|
if (typeof window !== "undefined") {
|
|
9
7
|
const redirectUrl = `https://auth.oxy.so/?callback=${encodeURIComponent(callback)}`;
|
|
10
|
-
set("clientKey", ""); // Clear the clientKey before redirecting
|
|
11
8
|
window.location.href = redirectUrl;
|
|
12
9
|
}
|
|
13
10
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientKey.d.ts","sourceRoot":"","sources":["../../src/hooks/getClientKey.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,wBAuBxB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const getClientKey = async () => {
|
|
2
|
+
const iframe = document.createElement("iframe");
|
|
3
|
+
iframe.src = "https://auth.oxy.so/share-session";
|
|
4
|
+
iframe.style.display = "none";
|
|
5
|
+
document.body.appendChild(iframe);
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const messageHandler = (event) => {
|
|
8
|
+
if (event.origin === "https://auth.oxy.so" && event.data.clientKey) {
|
|
9
|
+
window.removeEventListener("message", messageHandler);
|
|
10
|
+
document.body.removeChild(iframe);
|
|
11
|
+
resolve(event.data.clientKey);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
window.addEventListener("message", messageHandler);
|
|
15
|
+
iframe.onload = () => {
|
|
16
|
+
iframe.contentWindow?.postMessage({ action: "getClientKey" }, "https://auth.oxy.so");
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAOA,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,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,QAAQ,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,kBAAkB,EAAE,OAAO,CAAC;KAC7B,CAAC;CACH;AAED,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,eAAe,2EAmD1B,CAAC;AAEH,iBAAS,aAAa;;;;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 { getClientKey } from "./getClientKey";
|
|
4
5
|
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 {
|
|
@@ -15,19 +15,8 @@ export const useSessionStore = create((set) => {
|
|
|
15
15
|
set({ status: "loading" });
|
|
16
16
|
isFirstFetch = false;
|
|
17
17
|
}
|
|
18
|
-
// Get the
|
|
19
|
-
|
|
20
|
-
let clientKey = urlParams.get("clientKey");
|
|
21
|
-
// If the session ID was not found in the URL parameters, get it from local storage
|
|
22
|
-
if (!clientKey) {
|
|
23
|
-
const { get } = useCrossDomainStorage();
|
|
24
|
-
clientKey = get("clientKey");
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// If the session ID was found in the URL parameters, set it in local storage
|
|
28
|
-
const { set } = useCrossDomainStorage();
|
|
29
|
-
set("clientKey", clientKey);
|
|
30
|
-
}
|
|
18
|
+
// Get the client key using the getClientKey function
|
|
19
|
+
let clientKey = await getClientKey();
|
|
31
20
|
const response = await axios.get(OXY_AUTH_URL + "/api/session/" + clientKey);
|
|
32
21
|
if (response.status !== 200) {
|
|
33
22
|
throw new Error(`Unexpected response status: ${response.status}`);
|