@oxyhq/services 0.0.79 → 0.0.81
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 +32 -29
- 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,kGAyI/B,CAAC"}
|
|
@@ -4,30 +4,20 @@ import { useEffect, useState } from "react";
|
|
|
4
4
|
import { motion } from "framer-motion";
|
|
5
5
|
import useOxySession from "../../hooks/useOxySession";
|
|
6
6
|
import { forwardRef } from "react";
|
|
7
|
-
import { HiOutlinePlus } from "react-icons/hi";
|
|
8
|
-
import { PiSignOutBold } from "react-icons/pi";
|
|
9
7
|
import { AiOutlineClose } from "react-icons/ai";
|
|
10
8
|
import { Avatar } from "../../features/profile";
|
|
11
9
|
import getUserById from "../../hooks/getUserById";
|
|
12
|
-
import useCrossDomainStorage from "../../hooks/useCrossDomainStorage";
|
|
13
10
|
import styles from "./styles/account-switcher-modal.module.css";
|
|
14
11
|
export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
15
12
|
const { onClose } = props;
|
|
16
13
|
const { session } = useOxySession();
|
|
17
|
-
const { get, set } = useCrossDomainStorage();
|
|
18
14
|
const [user, setUser] = useState(null);
|
|
19
15
|
const [error, setError] = useState(null);
|
|
20
16
|
useEffect(() => {
|
|
21
17
|
const fetchUser = async () => {
|
|
22
18
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const fetchedUser = await getUserById(clientKey);
|
|
26
|
-
setUser(fetchedUser);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
setError("Client key is missing");
|
|
30
|
-
}
|
|
19
|
+
const fetchedUser = await getUserById(session?.user?.id);
|
|
20
|
+
setUser(fetchedUser);
|
|
31
21
|
}
|
|
32
22
|
catch (error) {
|
|
33
23
|
if (error instanceof Error) {
|
|
@@ -41,13 +31,12 @@ export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
|
41
31
|
if (session) {
|
|
42
32
|
fetchUser();
|
|
43
33
|
}
|
|
44
|
-
}, [session
|
|
34
|
+
}, [session]);
|
|
45
35
|
if (!session)
|
|
46
36
|
return null;
|
|
47
37
|
const handleBackdropClick = (e) => {
|
|
48
38
|
e.stopPropagation();
|
|
49
39
|
if (e.currentTarget === e.target) {
|
|
50
|
-
set("clientKey", "");
|
|
51
40
|
onClose();
|
|
52
41
|
}
|
|
53
42
|
};
|
|
@@ -55,23 +44,37 @@ export const AccountSwitcherModal = forwardRef((props, ref) => {
|
|
|
55
44
|
ease: "easeInOut",
|
|
56
45
|
duration: 0.2,
|
|
57
46
|
}, className: styles.container, role: "group", onClick: handleBackdropClick, ref: ref },
|
|
47
|
+
React.createElement("div", { className: "w-full max-w-md mx-auto bg-white shadow-lg rounded-xl" },
|
|
48
|
+
React.createElement("div", { className: "flex justify-between items-center p-4 border-b" },
|
|
49
|
+
React.createElement("div", { className: "flex items-center space-x-2" },
|
|
50
|
+
React.createElement(Avatar, { userImage: session?.user?.avatar, className: "h-10 w-10 rounded-full object-center", draggable: false, alt: "avatar" }),
|
|
51
|
+
React.createElement("p", { className: "text-sm font-medium" }, session?.user?.email)),
|
|
52
|
+
React.createElement("button", { className: "p-2 hover:bg-gray-100 rounded-full" }, "Close")),
|
|
53
|
+
React.createElement("div", { className: "p-4 space-y-4" },
|
|
54
|
+
React.createElement("h2", { className: "text-2xl font-bold" }, "Hi, Shiv!"),
|
|
55
|
+
React.createElement("button", { className: "w-full py-2 px-4 border border-gray-300 rounded-md text-blue-600 hover:bg-gray-50" }, "Manage your Google Account"),
|
|
56
|
+
React.createElement("button", { className: "w-full py-2 px-4 border border-gray-300 rounded-md text-left flex justify-between items-center hover:bg-gray-50" }, "Show more accounts"),
|
|
57
|
+
React.createElement("div", { className: "pt-2" },
|
|
58
|
+
React.createElement("p", { className: "text-sm text-gray-500 mb-2" }, "More from Oxy Services"),
|
|
59
|
+
React.createElement("div", { className: "space-y-2" }, [
|
|
60
|
+
{ icon: null, text: "Search history", rightText: "Saving" },
|
|
61
|
+
{ icon: null, text: "Delete last 15 minutes" },
|
|
62
|
+
{ icon: null, text: "Interests" },
|
|
63
|
+
{ icon: null, text: "Search personalisation" },
|
|
64
|
+
{ icon: null, text: "SafeSearch", rightText: "Blurring on" },
|
|
65
|
+
{ icon: null, text: "Language", rightText: "English" },
|
|
66
|
+
].map((item, index) => (React.createElement("button", { key: index, className: "w-full py-2 px-4 flex items-center justify-start hover:bg-gray-100 rounded-md" },
|
|
67
|
+
item.icon &&
|
|
68
|
+
React.createElement(item.icon, {
|
|
69
|
+
className: "h-5 w-5 mr-3",
|
|
70
|
+
}),
|
|
71
|
+
React.createElement("span", { className: "flex-grow text-left" }, item.text),
|
|
72
|
+
item.rightText && (React.createElement("span", { className: "text-sm text-gray-500" }, item.rightText)))))))),
|
|
73
|
+
React.createElement("div", { className: "flex justify-between p-4 border-t" },
|
|
74
|
+
React.createElement("button", { className: "w-1/2 py-2 px-4 flex items-center justify-center hover:bg-gray-100 rounded-md" }, "More settings"),
|
|
75
|
+
React.createElement("button", { className: "w-1/2 py-2 px-4 flex items-center justify-center hover:bg-gray-100 rounded-md" }, "Help"))),
|
|
58
76
|
React.createElement("button", { className: "absolute right-3 top-3 rounded-full bg-indigo-50 p-1 hover:bg-zinc-200", onClick: onClose },
|
|
59
77
|
React.createElement(AiOutlineClose, { className: "h-5 w-5 rounded-full stroke-2 text-zinc-700" })),
|
|
60
|
-
React.createElement("p", null, session?.user?.email),
|
|
61
|
-
React.createElement("div", { className: "h-20 w-20 rounded-full border" },
|
|
62
|
-
React.createElement(Avatar, { userImage: session?.user?.avatar, className: "h-full w-full rounded-full object-center", draggable: false, alt: "avatar" })),
|
|
63
|
-
React.createElement("h2", { className: "md:text-2xl text-xl font-normal" },
|
|
64
|
-
"Hi, ",
|
|
65
|
-
session?.user?.name,
|
|
66
|
-
"!"),
|
|
67
|
-
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"),
|
|
68
|
-
React.createElement("div", { className: "flex space-x-1" },
|
|
69
|
-
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" },
|
|
70
|
-
React.createElement(HiOutlinePlus, { className: "h-7 w-7 rounded-full bg-indigo-50 p-1 text-blue-500" }),
|
|
71
|
-
React.createElement("span", null, "Add account")),
|
|
72
|
-
React.createElement("button", { className: "md:w-44 flex w-36 items-center space-x-2 rounded-r-full bg-white py-3 pl-3 hover:bg-zinc-200" },
|
|
73
|
-
React.createElement(PiSignOutBold, { className: "h-6 w-6" }),
|
|
74
|
-
React.createElement("span", null, "Sign out"))),
|
|
75
78
|
React.createElement("div", { className: "flex h-10 items-center space-x-2 text-xs" },
|
|
76
79
|
React.createElement("a", { href: "https://oxy.so/company/transparency/policies/privacy", target: "_blank", rel: "noopener noreferrer" }, "Privacy policy"),
|
|
77
80
|
React.createElement("span", { className: "-mt-[3px]" }, " . "),
|
|
@@ -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}`);
|