@oxyhq/services 0.0.69 → 0.0.71
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 +4 -2
- package/dist/components/auth/AccountSwitcherModal.d.ts.map +1 -1
- package/dist/components/auth/AccountSwitcherModal.js +7 -7
- package/dist/components/auth/SessionOwnerButton.d.ts.map +1 -1
- package/dist/components/auth/SessionOwnerButton.js +1 -1
- package/dist/components/auth/styles/account-switcher-modal.module.css +35 -0
- package/dist/components/auth/styles/account-switcher-modal.module.css.map +1 -0
- package/dist/hooks/get-user.d.ts.map +1 -1
- package/dist/hooks/get-user.js +18 -15
- package/dist/hooks/useOxySession.d.ts +2 -0
- package/dist/hooks/useOxySession.d.ts.map +1 -1
- package/dist/hooks/useOxySession.js +42 -55
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
2
|
+
interface AccountSwitcherModalProps {
|
|
3
3
|
onClose: () => void;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
|
+
export declare const AccountSwitcherModal: React.ForwardRefExoticComponent<AccountSwitcherModalProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export {};
|
|
5
7
|
//# sourceMappingURL=AccountSwitcherModal.d.ts.map
|
|
@@ -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,
|
|
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,8 +9,9 @@ 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 styles from "./styles/
|
|
13
|
-
export const AccountSwitcherModal = forwardRef((
|
|
12
|
+
import styles from "./styles/account-switcher-modal.module.css";
|
|
13
|
+
export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
14
|
+
const { onClose } = props;
|
|
14
15
|
const { session } = useOxySession();
|
|
15
16
|
const [user, setUser] = useState(null);
|
|
16
17
|
const [error, setError] = useState(null);
|
|
@@ -44,7 +45,7 @@ export const AccountSwitcherModal = forwardRef(({ onClose }, ref) => {
|
|
|
44
45
|
return (React.createElement(motion.div, { initial: { opacity: 0, y: "100%" }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: "100%" }, transition: {
|
|
45
46
|
ease: "easeInOut",
|
|
46
47
|
duration: 0.2,
|
|
47
|
-
}, className: styles.container, role: "group", onClick: handleBackdropClick },
|
|
48
|
+
}, className: styles.container, role: "group", onClick: handleBackdropClick, ref: ref },
|
|
48
49
|
React.createElement("button", { className: "absolute right-3 top-3 rounded-full bg-indigo-50 p-1 hover:bg-zinc-200", onClick: onClose },
|
|
49
50
|
React.createElement(AiOutlineClose, { className: "h-5 w-5 rounded-full stroke-2 text-zinc-700" })),
|
|
50
51
|
React.createElement("p", null, session?.user?.email),
|
|
@@ -54,7 +55,7 @@ export const AccountSwitcherModal = forwardRef(({ onClose }, ref) => {
|
|
|
54
55
|
"Hi, ",
|
|
55
56
|
session?.user?.name,
|
|
56
57
|
"!"),
|
|
57
|
-
React.createElement("
|
|
58
|
+
React.createElement("a", { href: "https://accounts.oxy.so", target: "_blank", rel: "noopener noreferrer", className: "rounded-full border border-black px-7 py-2 text-blue-500 hover:bg-[#d3dfee]" }, "Manage your Oxy Account"),
|
|
58
59
|
React.createElement("div", { className: "flex space-x-1" },
|
|
59
60
|
React.createElement("button", { className: "md:w-44 flex w-36 items-center space-x-2 rounded-l-full bg-white py-3 pl-3 hover:bg-zinc-200" },
|
|
60
61
|
React.createElement(HiOutlinePlus, { className: "h-7 w-7 rounded-full bg-indigo-50 p-1 text-blue-500" }),
|
|
@@ -63,9 +64,8 @@ export const AccountSwitcherModal = forwardRef(({ onClose }, ref) => {
|
|
|
63
64
|
React.createElement(PiSignOutBold, { className: "h-6 w-6" }),
|
|
64
65
|
React.createElement("span", null, "Sign out"))),
|
|
65
66
|
React.createElement("div", { className: "flex h-10 items-center space-x-2 text-xs" },
|
|
66
|
-
React.createElement("
|
|
67
|
+
React.createElement("a", { href: "https://oxy.so/company/transparency/policies/privacy", target: "_blank", rel: "noopener noreferrer" }, "Privacy policy"),
|
|
67
68
|
React.createElement("span", { className: "-mt-[3px]" }, " . "),
|
|
68
|
-
" ",
|
|
69
|
-
React.createElement("span", null, "Terms of service"))));
|
|
69
|
+
React.createElement("a", { href: "https://oxy.so/company/transparency/policies/terms-of-service", target: "_blank", rel: "noopener noreferrer" }, "Terms of service"))));
|
|
70
70
|
});
|
|
71
71
|
AccountSwitcherModal.displayName = "AccountSwitcherModal";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionOwnerButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SessionOwnerButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"SessionOwnerButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SessionOwnerButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B,eAAO,MAAM,kBAAkB,yBAoD9B,CAAC"}
|
|
@@ -31,5 +31,5 @@ export const SessionOwnerButton = () => {
|
|
|
31
31
|
React.createElement("div", { className: "hidden fill-secondary-100 xxl:inline [&>svg]:size-h2" },
|
|
32
32
|
React.createElement(DotIcon, null))),
|
|
33
33
|
React.createElement(AnimatePresence, null, isModalOpen && (React.createElement(Modal, { onClose: () => setIsModalOpen(false), background: "none", minViewportWidth: 500 },
|
|
34
|
-
React.createElement(AccountSwitcherModal, {
|
|
34
|
+
React.createElement(AccountSwitcherModal, { onClose: () => setIsModalOpen(false) }))))));
|
|
35
35
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
width: 300px;
|
|
3
|
+
background-color: var(--clr-background);
|
|
4
|
+
box-shadow: 0 0rem 10px -2px var(--clr-tertiary);
|
|
5
|
+
border-radius: 1rem;
|
|
6
|
+
padding: 0.8em 0;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
position: fixed;
|
|
9
|
+
top: 0;
|
|
10
|
+
bottom: 0;
|
|
11
|
+
left: 0;
|
|
12
|
+
right: 0;
|
|
13
|
+
margin: auto;
|
|
14
|
+
a {
|
|
15
|
+
font-size: var(--fs-milli);
|
|
16
|
+
font-weight: var(--fw-700);
|
|
17
|
+
display: block;
|
|
18
|
+
padding: 0.8em 1em;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
transition: background-color 0.1s ease-in-out;
|
|
21
|
+
&:hover {
|
|
22
|
+
background-color: var(--clr-trends-hover);
|
|
23
|
+
}
|
|
24
|
+
&:active {
|
|
25
|
+
background-color: var(--clr-trends-active);
|
|
26
|
+
}
|
|
27
|
+
&:focus-visible {
|
|
28
|
+
background-color: var(--clr-trends-hover);
|
|
29
|
+
outline: 2px solid var(--clr-primary-disabled);
|
|
30
|
+
outline-offset: -2px;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/*# sourceMappingURL=account-switcher-modal.module.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../../../../src/components/auth/styles/account-switcher-modal.module.css"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;IACE;IACA;IACA;IACA;IACA;IACA;IAEA;MACE;;IAGF;MACE;;IAGF;MACE;MACA;MACA","file":"account-switcher-modal.module.css"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-user.d.ts","sourceRoot":"","sources":["../../src/hooks/get-user.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,OAAc,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"get-user.d.ts","sourceRoot":"","sources":["../../src/hooks/get-user.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,OAAc,MAAM,GAAG,SAAS,iBA0BnD,CAAC"}
|
package/dist/hooks/get-user.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { OXY_AUTH_URL } from "../config";
|
|
3
3
|
export const getUser = async (id) => {
|
|
4
|
+
if (!id) {
|
|
5
|
+
throw new Error("User ID is required");
|
|
6
|
+
}
|
|
4
7
|
try {
|
|
5
8
|
const response = await axios.get(OXY_AUTH_URL + `/api/users/${id}`);
|
|
6
9
|
return response.data;
|
|
7
10
|
}
|
|
8
11
|
catch (error) {
|
|
9
|
-
if (error
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
if (axios.isAxiosError(error)) {
|
|
13
|
+
if (error.response) {
|
|
14
|
+
// Server responded with a status code outside of 2xx
|
|
15
|
+
throw new Error(`Server responded with status ${error.response.status}: ${error.response.data}`);
|
|
16
|
+
}
|
|
17
|
+
else if (error.request) {
|
|
18
|
+
// Request was made but no response received
|
|
19
|
+
throw new Error("No response received from server");
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// Error setting up the request
|
|
23
|
+
throw new Error(`Axios error: ${error.message}`);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
else {
|
|
23
|
-
//
|
|
24
|
-
|
|
27
|
+
// Non-Axios error
|
|
28
|
+
throw error;
|
|
25
29
|
}
|
|
26
|
-
console.log(error.config);
|
|
27
30
|
}
|
|
28
31
|
};
|
|
@@ -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,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;
|
|
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,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;QAC5B,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,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,2EAiDzB,CAAC;AAEJ,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -3,71 +3,58 @@ import axios from "axios";
|
|
|
3
3
|
import { create } from "zustand";
|
|
4
4
|
import localforage from "localforage";
|
|
5
5
|
import { OXY_AUTH_URL } from "../config";
|
|
6
|
-
export const useSessionStore = create((set) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
set({ status: "loading" });
|
|
16
|
-
isFirstFetch = false;
|
|
17
|
-
}
|
|
18
|
-
// Get the session ID from the URL parameters if it exists
|
|
6
|
+
export const useSessionStore = create((set) => ({
|
|
7
|
+
session: null,
|
|
8
|
+
status: "idle",
|
|
9
|
+
error: null,
|
|
10
|
+
fetchSessionData: async () => {
|
|
11
|
+
set({ status: "loading" });
|
|
12
|
+
try {
|
|
13
|
+
let clientKey = null;
|
|
14
|
+
if (typeof window !== "undefined") {
|
|
19
15
|
const urlParams = new URLSearchParams(window.location.search);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// If the session ID was found in the URL parameters, set it in local storage
|
|
27
|
-
await localforage.setItem("clientKey", clientKey);
|
|
28
|
-
}
|
|
29
|
-
const response = await axios.get(OXY_AUTH_URL + "/api/session/" + clientKey);
|
|
30
|
-
if (response.status !== 200) {
|
|
31
|
-
throw new Error(`Unexpected response status: ${response.status}`);
|
|
32
|
-
}
|
|
33
|
-
set({ session: response.data, status: "success" });
|
|
16
|
+
clientKey = urlParams.get("clientKey");
|
|
17
|
+
}
|
|
18
|
+
if (!clientKey) {
|
|
19
|
+
clientKey = await localforage.getItem("clientKey");
|
|
34
20
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
else {
|
|
22
|
+
await localforage.setItem("clientKey", clientKey);
|
|
23
|
+
}
|
|
24
|
+
if (!clientKey) {
|
|
25
|
+
throw new Error("Client key not found.");
|
|
26
|
+
}
|
|
27
|
+
const response = await axios.get(`${OXY_AUTH_URL}/api/session/${clientKey}`);
|
|
28
|
+
if (response.status !== 200) {
|
|
29
|
+
throw new Error(`Unexpected response status: ${response.status}`);
|
|
30
|
+
}
|
|
31
|
+
set({ session: response.data, status: "success", error: null });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
let errorMessage = "An error occurred while loading the session data.";
|
|
35
|
+
if (axios.isAxiosError(error)) {
|
|
36
|
+
if (error.response) {
|
|
37
|
+
errorMessage = `API error: ${error.response.status} ${error.response.statusText}`;
|
|
38
|
+
}
|
|
39
|
+
else if (error.request) {
|
|
40
|
+
errorMessage = "Network error: No response received from server.";
|
|
55
41
|
}
|
|
56
42
|
else {
|
|
57
|
-
|
|
58
|
-
error: "An unknown error occurred while loading the session data.",
|
|
59
|
-
status: "error",
|
|
60
|
-
});
|
|
43
|
+
errorMessage = `Axios error: ${error.message}`;
|
|
61
44
|
}
|
|
62
45
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
46
|
+
else if (error instanceof Error) {
|
|
47
|
+
errorMessage = `Error: ${error.message}`;
|
|
48
|
+
}
|
|
49
|
+
set({ error: errorMessage, status: "error", session: null });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
66
53
|
function useOxySession() {
|
|
67
54
|
const { session, status, error, fetchSessionData } = useSessionStore();
|
|
68
55
|
useEffect(() => {
|
|
69
56
|
fetchSessionData();
|
|
70
|
-
}, []);
|
|
57
|
+
}, [fetchSessionData]);
|
|
71
58
|
return { session, status, error };
|
|
72
59
|
}
|
|
73
60
|
export default useOxySession;
|