@oxyhq/services 0.0.4 → 0.0.6
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/SignInButton.d.ts +7 -0
- package/dist/components/auth/SignInButton.d.ts.map +1 -0
- package/dist/components/auth/SignInButton.js +37 -0
- package/dist/components/auth/index.d.ts +3 -0
- package/dist/components/auth/index.d.ts.map +1 -0
- package/dist/components/auth/index.js +2 -0
- package/dist/hooks/useOxySession.d.ts +26 -0
- package/dist/hooks/useOxySession.d.ts.map +1 -0
- package/dist/hooks/useOxySession.js +45 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +6 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignInButton.d.ts","sourceRoot":"","sources":["../../../src/components/auth/SignInButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAM7C,CAAC;AAmCF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
const SignInButton = ({ onClick }) => {
|
|
3
|
+
return (React.createElement("button", { onClick: onClick, style: styles.button }, "Sign in with Oxy"));
|
|
4
|
+
};
|
|
5
|
+
const styles = {
|
|
6
|
+
button: {
|
|
7
|
+
padding: "0.7em",
|
|
8
|
+
borderRadius: "100vmax",
|
|
9
|
+
fontSize: "var(--fs-milli)",
|
|
10
|
+
fontWeight: "var(--fw-700)",
|
|
11
|
+
color: "var(--clr-dark)",
|
|
12
|
+
backgroundColor: "var(--clr-light)",
|
|
13
|
+
border: "1px solid var(--clr-auth-border)",
|
|
14
|
+
display: "flex",
|
|
15
|
+
justifyContent: "center",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
cursor: "pointer",
|
|
18
|
+
transition: "background 0.2s ease-in-out",
|
|
19
|
+
"&:hover": {
|
|
20
|
+
backgroundColor: "var(--clr-auth-button-hover)",
|
|
21
|
+
},
|
|
22
|
+
"&:active": {
|
|
23
|
+
backgroundColor: "var(--clr-auth-button-active)",
|
|
24
|
+
},
|
|
25
|
+
"&:focus-visible": {
|
|
26
|
+
outline: "2px solid var(--clr-light)",
|
|
27
|
+
backgroundColor: "var(--clr-auth-button-hover)",
|
|
28
|
+
},
|
|
29
|
+
svg: {
|
|
30
|
+
width: "var(--fs-h2)",
|
|
31
|
+
height: "var(--fs-h2)",
|
|
32
|
+
fill: "var(--clr-dark)",
|
|
33
|
+
marginRight: "0.5em",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export default SignInButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface SessionModel {
|
|
2
|
+
user: {
|
|
3
|
+
id: string;
|
|
4
|
+
username: string;
|
|
5
|
+
name: string;
|
|
6
|
+
lastname: string;
|
|
7
|
+
email: string;
|
|
8
|
+
verified: boolean;
|
|
9
|
+
profile_image_url: string;
|
|
10
|
+
created_at: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
type SessionState = {
|
|
14
|
+
session: SessionModel | null;
|
|
15
|
+
status: string;
|
|
16
|
+
error: any;
|
|
17
|
+
fetchSessionData: () => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const useSessionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SessionState>>;
|
|
20
|
+
declare function useOxySession(): {
|
|
21
|
+
session: SessionModel | null;
|
|
22
|
+
status: string;
|
|
23
|
+
error: any;
|
|
24
|
+
};
|
|
25
|
+
export default useOxySession;
|
|
26
|
+
//# sourceMappingURL=useOxySession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAOA,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,iBAAiB,EAAE,MAAM,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;KACpB,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,2EAmC1B,CAAC;AAEH,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { create } from "zustand";
|
|
4
|
+
import localforage from "localforage";
|
|
5
|
+
import { OXY_AUTH_URL } from "../config";
|
|
6
|
+
export const useSessionStore = create((set) => {
|
|
7
|
+
let isFirstFetch = true;
|
|
8
|
+
return {
|
|
9
|
+
session: null,
|
|
10
|
+
status: "loading",
|
|
11
|
+
error: null,
|
|
12
|
+
fetchSessionData: async () => {
|
|
13
|
+
try {
|
|
14
|
+
if (isFirstFetch) {
|
|
15
|
+
set({ status: "loading" });
|
|
16
|
+
isFirstFetch = false;
|
|
17
|
+
}
|
|
18
|
+
// Get the session ID from the URL parameters if it exists
|
|
19
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
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
|
+
clientKey = await localforage.getItem("clientKey");
|
|
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
|
+
set({ session: response.data, status: "success" });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
set({ error, status: "error" });
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
function useOxySession() {
|
|
39
|
+
const { session, status, error, fetchSessionData } = useSessionStore();
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
fetchSessionData();
|
|
42
|
+
}, []);
|
|
43
|
+
return { session, status, error };
|
|
44
|
+
}
|
|
45
|
+
export default useOxySession;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import useOxySession from "./hooks/useOxySession";
|
|
2
2
|
import getUserById from "./hooks/getUserById";
|
|
3
|
-
|
|
3
|
+
import SignInButton from "./components/auth/SignInButton";
|
|
4
|
+
export { useOxySession, getUserById, SignInButton };
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,WAAW,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAC9C,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxyhq/services",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://oxy.so/",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,21 +24,22 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/next-auth": "^3.15.0",
|
|
26
26
|
"@types/node": "^20.11.17",
|
|
27
|
-
"@types/react": "^18.
|
|
27
|
+
"@types/react": "^18.3.3",
|
|
28
|
+
"@types/react-dom": "^18.3.0",
|
|
28
29
|
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
29
30
|
"@typescript-eslint/parser": "^7.0.1",
|
|
30
31
|
"autoprefixer": "^10.4.17",
|
|
31
32
|
"eslint": "^8.56.0",
|
|
32
33
|
"postcss": "^8.4.35",
|
|
33
34
|
"tailwindcss": "^3.4.1",
|
|
34
|
-
"typescript": "^5.
|
|
35
|
+
"typescript": "^5.4.5"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"axios": "^1.6.8",
|
|
38
39
|
"dotenv": "^16.4.5",
|
|
39
40
|
"localforage": "^1.10.0",
|
|
40
|
-
"react": "^18.
|
|
41
|
-
"react-dom": "^18.
|
|
41
|
+
"react": "^18.3.1",
|
|
42
|
+
"react-dom": "^18.3.1",
|
|
42
43
|
"zod": "^3.23.8",
|
|
43
44
|
"zustand": "^4.5.2"
|
|
44
45
|
}
|