diff --git a/Documentation/docusaurus.config.ts b/Documentation/docusaurus.config.ts index 11379bc..6b988b8 100644 --- a/Documentation/docusaurus.config.ts +++ b/Documentation/docusaurus.config.ts @@ -57,7 +57,7 @@ const config: Config = { title: '', logo: { alt: 'FastPocket logo', - src: 'https://fastpocket.dev/images/combination-icon.png', + src: 'img/combination-icon.png', href: 'https://fastpocket.dev/' }, items: [ @@ -79,6 +79,10 @@ const config: Config = { darkTheme: prismThemes.dracula, }, } satisfies Preset.ThemeConfig, + + customFields: { + 'POCKETBASE_URL': process.env.POCKETBASE_URL, + }, }; export default config; diff --git a/Documentation/package-lock.json b/Documentation/package-lock.json index b06b33f..e911164 100644 --- a/Documentation/package-lock.json +++ b/Documentation/package-lock.json @@ -12,6 +12,7 @@ "@docusaurus/preset-classic": "3.1.1", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "pocketbase": "^0.21.1", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", "react-dom": "^18.0.0" @@ -10987,6 +10988,11 @@ "node": ">=4" } }, + "node_modules/pocketbase": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.21.1.tgz", + "integrity": "sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==" + }, "node_modules/postcss": { "version": "8.4.35", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz", @@ -22257,6 +22263,11 @@ } } }, + "pocketbase": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.21.1.tgz", + "integrity": "sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==" + }, "postcss": { "version": "8.4.35", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz", diff --git a/Documentation/package.json b/Documentation/package.json index d7ef927..1812cb0 100644 --- a/Documentation/package.json +++ b/Documentation/package.json @@ -19,6 +19,7 @@ "@docusaurus/preset-classic": "3.1.1", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "pocketbase": "^0.21.1", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", "react-dom": "^18.0.0" diff --git a/Documentation/src/theme/ColorModeToggle/index.js b/Documentation/src/theme/ColorModeToggle/index.js new file mode 100644 index 0000000..019c5cc --- /dev/null +++ b/Documentation/src/theme/ColorModeToggle/index.js @@ -0,0 +1,14 @@ +import React from 'react'; +import ColorModeToggle from '@theme-original/ColorModeToggle'; +import {logout} from '../pocketbase'; + +export default function ColorModeToggleWrapper(props) { + return ( + <> + + logout(() => window.location.reload())}> + Logout + + + ); +} \ No newline at end of file diff --git a/Documentation/src/theme/Root.js b/Documentation/src/theme/Root.js new file mode 100644 index 0000000..087d7f5 --- /dev/null +++ b/Documentation/src/theme/Root.js @@ -0,0 +1,99 @@ +import React, { useState } from "react"; +import { signIn, auth } from "./pocketbase"; + +export default function Root({ children }) { + const [userAuth, setUserAuth] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [loading, setLoading] = useState(false); + + const handleSubmit = async (event) => { + event.preventDefault(); + setLoading(true) + await signIn(email,password) + setLoading(false) + }; + + auth.onChange(async function (user) { + if (user !== null) { + setUserAuth(user); + } + }); + + return ( + <> + {userAuth != "" ? ( + <>{children} + ) : ( +
+
+ +

Docs

+ + setEmail(e.target.value)} + style={{ + marginBottom: "10px", + padding: "5px", + borderRadius: "5px", + border: "1px solid #ccc", + }} + /> + + setPassword(e.target.value)} + style={{ + marginBottom: "10px", + padding: "5px", + borderRadius: "5px", + border: "1px solid #ccc", + }} + /> + +
+
+ )} + + ); +} diff --git a/Documentation/src/theme/pocketbase.js b/Documentation/src/theme/pocketbase.js new file mode 100644 index 0000000..c89604f --- /dev/null +++ b/Documentation/src/theme/pocketbase.js @@ -0,0 +1,22 @@ +import PocketBase from "pocketbase"; + +const app = (() => { + const POCKETBASE_URL = "https://fastpocket.fly.dev" + "/"; + return new PocketBase(POCKETBASE_URL); +})(); + +export const auth = app.authStore; + +export const logout = (afterAction = () => {}) => { + app.authStore.clear(); + afterAction(null); +}; + +export const signIn = async (email, password) => { + try { + await app.collection("user").authWithPassword(email, password); + } catch (err) { + console.error(err); + alert(err.message); + } +}; diff --git a/Documentation/static/img/combination-icon.png b/Documentation/static/img/combination-icon.png new file mode 100644 index 0000000..0a58667 Binary files /dev/null and b/Documentation/static/img/combination-icon.png differ