diff --git a/app/src/adapter/nextjs/nextjs.adapter.ts b/app/src/adapter/nextjs/nextjs.adapter.ts index eaee4ab..65d5ffa 100644 --- a/app/src/adapter/nextjs/nextjs.adapter.ts +++ b/app/src/adapter/nextjs/nextjs.adapter.ts @@ -2,7 +2,9 @@ import type { IncomingMessage, ServerResponse } from "node:http"; import { Api, type App } from "bknd"; import { type FrameworkBkndConfig, createFrameworkApp, nodeRequestToRequest } from "../index"; -export type NextjsBkndConfig = FrameworkBkndConfig; +export type NextjsBkndConfig = FrameworkBkndConfig & { + cleanSearch?: string[]; +}; type GetServerSidePropsContext = { req: IncomingMessage; @@ -32,10 +34,13 @@ export function withApi(handler: (ctx: GetServerSidePropsContext & { api: Api }; } -function getCleanRequest(req: Request) { - // clean search params from "route" attribute +function getCleanRequest( + req: Request, + { cleanSearch = ["route"] }: Pick +) { const url = new URL(req.url); - url.searchParams.delete("route"); + cleanSearch?.forEach((k) => url.searchParams.delete(k)); + return new Request(url.toString(), { method: req.method, headers: req.headers, @@ -44,12 +49,12 @@ function getCleanRequest(req: Request) { } let app: App; -export function serve(config: NextjsBkndConfig = {}) { +export function serve({ cleanSearch, ...config }: NextjsBkndConfig = {}) { return async (req: Request) => { if (!app) { app = await createFrameworkApp(config); } - const request = getCleanRequest(req); + const request = getCleanRequest(req, { cleanSearch }); return app.fetch(request, process.env); }; } diff --git a/bun.lockb b/bun.lockb index 09c5c1a..82c57ef 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/examples/plasmic/.gitignore b/examples/plasmic/.gitignore deleted file mode 100644 index d0d878e..0000000 --- a/examples/plasmic/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.next \ No newline at end of file diff --git a/examples/plasmic/index.html b/examples/plasmic/index.html new file mode 100644 index 0000000..e4b78ea --- /dev/null +++ b/examples/plasmic/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/examples/plasmic/next-env.d.ts b/examples/plasmic/next-env.d.ts deleted file mode 100644 index a4a7b3f..0000000 --- a/examples/plasmic/next-env.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/// - -// NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/examples/plasmic/next.config.ts b/examples/plasmic/next.config.ts deleted file mode 100644 index 3915163..0000000 --- a/examples/plasmic/next.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { NextConfig } from "next"; - -const nextConfig: NextConfig = { - /* config options here */ - reactStrictMode: true, -}; - -export default nextConfig; diff --git a/examples/plasmic/package.json b/examples/plasmic/package.json index d530a6c..49a4f36 100644 --- a/examples/plasmic/package.json +++ b/examples/plasmic/package.json @@ -1,26 +1,17 @@ { - "name": "plasmic-nextjs", - "version": "0.1.0", + "name": "plasmic-wouter", "private": true, + "version": "0.0.0", + "type": "module", "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start", - "lint": "next lint" + "dev": "vite", + "build": "vite build", + "preview": "vite preview" }, "dependencies": { - "@plasmicapp/loader-nextjs": "^1.0.409", - "bknd": "workspace:*", "@bknd/plasmic": "workspace:*", - "next": "15.0.4", - "react": "^18.3.1", - "react-dom": "^18.3.1" + "@plasmicapp/loader-react": "^1.0.373", + "bknd": "workspace:*" }, - "devDependencies": { - "typescript": "^5", - "@types/node": "^20", - "@types/react": "^19", - "@types/react-dom": "^19", - "postcss": "^8" - } + "devDependencies": {} } diff --git a/examples/plasmic/postcss.config.mjs b/examples/plasmic/postcss.config.mjs deleted file mode 100644 index 1a69fd2..0000000 --- a/examples/plasmic/postcss.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -/** @type {import('postcss-load-config').Config} */ -const config = { - plugins: { - tailwindcss: {}, - }, -}; - -export default config; diff --git a/examples/plasmic/public/vite.svg b/examples/plasmic/public/vite.svg new file mode 100644 index 0000000..e7b8dfb --- /dev/null +++ b/examples/plasmic/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/plasmic/src/App.tsx b/examples/plasmic/src/App.tsx new file mode 100644 index 0000000..da86876 --- /dev/null +++ b/examples/plasmic/src/App.tsx @@ -0,0 +1,88 @@ +import { registerAll } from "@bknd/plasmic"; +import { + type ComponentRenderData, + PlasmicCanvasHost, + PlasmicComponent, + type PlasmicComponentLoader, + PlasmicRootProvider, + initPlasmicLoader +} from "@plasmicapp/loader-react"; +import { Suspense, forwardRef, lazy, useEffect, useState } from "react"; +import { Route, Router, Switch } from "wouter"; +const Admin = lazy(() => import("./admin")); + +export const PLASMIC = initPlasmicLoader({ + projects: [ + { + id: import.meta.env.VITE_PLASMIC_ID as string, + token: import.meta.env.VITE_PLASMIC_TOKEN as string + } + ], + // Fetches the latest revisions, whether or not they were unpublished! + // Disable for production to ensure you render only published changes. + preview: true +}); + +registerAll(PLASMIC); + +export default function App() { + return ( + + + + + + + + + } /> + + + ); +} + +const CustomLink = forwardRef((props, ref) => { + //console.log("rendering custom link", props); + //return null; + if ("data-replace" in props) { + return ; + } + //return ; + // @ts-ignore it's because of the link + return ; +}); + +export function CatchAllPage({ + PLASMIC, + prefix = "" +}: { PLASMIC: PlasmicComponentLoader; prefix?: string }) { + const [loading, setLoading] = useState(true); + const [pageData, setPageData] = useState(null); + + const pathname = location.pathname.replace(prefix, ""); + const path = pathname.length === 0 ? "/" : pathname; + useEffect(() => { + async function load() { + const pageData = await PLASMIC.maybeFetchComponentData(path); + setPageData(pageData); + setLoading(false); + } + load().catch(console.error); + }, []); + + if (loading) { + return <>Loading ...; + } + if (!pageData) { + return <>Not found; + } + + const pageMeta = pageData.entryCompMetas[0]; + + // The page will already be cached from the `load` call above. + return ( + + + + ); +} diff --git a/examples/plasmic/src/admin.tsx b/examples/plasmic/src/admin.tsx new file mode 100644 index 0000000..031f951 --- /dev/null +++ b/examples/plasmic/src/admin.tsx @@ -0,0 +1,8 @@ +/// + +import { Admin } from "bknd/ui"; +import "bknd/dist/styles.css"; + +export default function AdminPage() { + return ; +} diff --git a/examples/plasmic/src/main.tsx b/examples/plasmic/src/main.tsx new file mode 100644 index 0000000..f328973 --- /dev/null +++ b/examples/plasmic/src/main.tsx @@ -0,0 +1,12 @@ +import { ClientProvider } from "bknd/client"; +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import App from "./App.tsx"; + +createRoot(document.getElementById("root")!).render( + + + + + +); diff --git a/examples/plasmic/src/pages/[[...catchall]].tsx b/examples/plasmic/src/pages/[[...catchall]].tsx deleted file mode 100644 index 4de4a49..0000000 --- a/examples/plasmic/src/pages/[[...catchall]].tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { PLASMIC } from "@/plasmic-init"; -import { - type ComponentRenderData, - PlasmicComponent, - PlasmicRootProvider, - extractPlasmicQueryData -} from "@plasmicapp/loader-nextjs"; -import type { GetServerSideProps } from "next"; -// biome-ignore lint/suspicious/noShadowRestrictedNames: -import Error from "next/error"; -import { useRouter } from "next/router"; -import * as React from "react"; - -export const getServerSideProps: GetServerSideProps = async (context) => { - const { catchall } = context.params ?? {}; - - // Convert the catchall param into a path string - const plasmicPath = - typeof catchall === "string" - ? catchall - : Array.isArray(catchall) - ? `/${catchall.join("/")}` - : "/"; - const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath); - if (!plasmicData) { - // This is some non-Plasmic catch-all page - return { - props: {} - }; - } - - // This is a path that Plasmic knows about. - const pageMeta = plasmicData.entryCompMetas[0]; - - // Cache the necessary data fetched for the page. - const queryCache = await extractPlasmicQueryData( - - {/* @ts-ignore */} - - - ); - - // Pass the data in as props. - return { - props: { plasmicData, queryCache } - }; -}; - -export default function CatchallPage(props: { - plasmicData?: ComponentRenderData; - queryCache?: Record; -}) { - const { plasmicData, queryCache } = props; - const router = useRouter(); - if (!plasmicData || plasmicData.entryCompMetas.length === 0) { - return ; - } - const pageMeta = plasmicData.entryCompMetas[0]; - return ( - // Pass in the data fetched in getStaticProps as prefetchedData - - {/* @ts-ignore */} - - - ); -} diff --git a/examples/plasmic/src/pages/_app.tsx b/examples/plasmic/src/pages/_app.tsx deleted file mode 100644 index 80eb165..0000000 --- a/examples/plasmic/src/pages/_app.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import "@/styles/globals.css"; -import { ClientProvider } from "bknd/client"; -import type { AppProps } from "next/app"; - -export default function App({ Component, pageProps }: AppProps) { - return ( - - - - ); -} diff --git a/examples/plasmic/src/pages/_document.tsx b/examples/plasmic/src/pages/_document.tsx deleted file mode 100644 index 628a733..0000000 --- a/examples/plasmic/src/pages/_document.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Html, Head, Main, NextScript } from "next/document"; - -export default function Document() { - return ( - - - -
- - - - ); -} diff --git a/examples/plasmic/src/pages/admin/[[...admin]].tsx b/examples/plasmic/src/pages/admin/[[...admin]].tsx deleted file mode 100644 index b854817..0000000 --- a/examples/plasmic/src/pages/admin/[[...admin]].tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { withApi } from "bknd/adapter/nextjs"; -// pages/admin/[[...admin]].tsx -import type { InferGetServerSidePropsType as InferProps } from "next"; -import dynamic from "next/dynamic"; -import "bknd/dist/styles.css"; - -const Admin = dynamic(() => import("bknd/ui").then((mod) => mod.Admin), { - ssr: false -}); - -export const getServerSideProps = withApi(async (context) => { - return { - props: { - user: context.api.getUser() - } - }; -}); - -export default function AdminPage({ user }: InferProps) { - if (typeof document === "undefined") return null; - return ; -} diff --git a/examples/plasmic/src/pages/api/[...route].ts b/examples/plasmic/src/pages/api/[...route].ts deleted file mode 100644 index f296f98..0000000 --- a/examples/plasmic/src/pages/api/[...route].ts +++ /dev/null @@ -1,16 +0,0 @@ -import { serve } from "bknd/adapter/nextjs"; - -export const config = { - runtime: "edge", - unstable_allowDynamic: ["**/*.js"] -}; - -export default serve({ - connection: { - type: "libsql", - config: { - url: process.env.DB_URL!, - authToken: process.env.DB_TOKEN! - } - } -}); diff --git a/examples/plasmic/src/pages/plasmic-host.tsx b/examples/plasmic/src/pages/plasmic-host.tsx deleted file mode 100644 index 7dac28d..0000000 --- a/examples/plasmic/src/pages/plasmic-host.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import * as React from 'react'; -import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs'; -import { PLASMIC } from '@/plasmic-init'; - -export default function PlasmicHost() { - return PLASMIC && ; -} \ No newline at end of file diff --git a/examples/plasmic/src/pages/test.tsx b/examples/plasmic/src/pages/test.tsx deleted file mode 100644 index 5b66ecc..0000000 --- a/examples/plasmic/src/pages/test.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import { useApi } from "bknd/client"; - -export default function Test() { - const api = useApi(undefined); - return
{api.baseUrl}
; -} diff --git a/examples/plasmic/src/plasmic-init.ts b/examples/plasmic/src/plasmic-init.ts deleted file mode 100644 index 9c77d9d..0000000 --- a/examples/plasmic/src/plasmic-init.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { initPlasmicLoader } from "@plasmicapp/loader-nextjs"; -import { loader } from "@bknd/plasmic"; - -export const PLASMIC = initPlasmicLoader({ - projects: [ - { - id: process.env.PLASMIC_ID!, - token: process.env.PLASMIC_TOKEN!, - } - ], - preview: true, //process.env.NODE_ENV === "development", -}) - -loader(PLASMIC); -/* -PLASMIC.registerComponent(BkndData, BkndDataMeta); -PLASMIC.registerGlobalContext(BkndContext, BkndContextMeta as any);*/ diff --git a/examples/plasmic/src/server.ts b/examples/plasmic/src/server.ts new file mode 100644 index 0000000..5ac41cb --- /dev/null +++ b/examples/plasmic/src/server.ts @@ -0,0 +1,43 @@ +import { App } from "bknd"; +import { serve } from "bknd/adapter/vite"; +import { boolean, em, entity, text } from "bknd/data"; +import { secureRandomString } from "bknd/utils"; + +export default serve({ + initialConfig: { + data: em({ + todos: entity("todos", { + title: text(), + done: boolean() + }) + }).toJSON(), + auth: { + enabled: true, + jwt: { + secret: secureRandomString(64) + } + } + }, + options: { + seed: async (ctx) => { + await ctx.em.mutator("todos" as any).insertMany([ + { title: "Learn bknd", done: true }, + { title: "Build something cool", done: false } + ]); + } + }, + // here we can hook into the app lifecycle events ... + beforeBuild: async (app) => { + app.emgr.onEvent( + App.Events.AppFirstBoot, + async () => { + // ... to create an initial user + await app.module.auth.createUser({ + email: "ds@bknd.io", + password: "12345678" + }); + }, + "sync" + ); + } +}); diff --git a/examples/plasmic/src/styles/globals.css b/examples/plasmic/src/styles/globals.css deleted file mode 100644 index b5c61c9..0000000 --- a/examples/plasmic/src/styles/globals.css +++ /dev/null @@ -1,3 +0,0 @@ -@tailwind base; -@tailwind components; -@tailwind utilities; diff --git a/examples/plasmic/tailwind.config.ts b/examples/plasmic/tailwind.config.ts deleted file mode 100644 index 109807b..0000000 --- a/examples/plasmic/tailwind.config.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Config } from "tailwindcss"; - -export default { - content: [ - "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", - "./src/components/**/*.{js,ts,jsx,tsx,mdx}", - "./src/app/**/*.{js,ts,jsx,tsx,mdx}", - ], - theme: { - extend: { - colors: { - background: "var(--background)", - foreground: "var(--foreground)", - }, - }, - }, - plugins: [], -} satisfies Config; diff --git a/examples/plasmic/tsconfig.json b/examples/plasmic/tsconfig.json index ecf7ecf..7c1c2d3 100644 --- a/examples/plasmic/tsconfig.json +++ b/examples/plasmic/tsconfig.json @@ -1,23 +1,21 @@ { "compilerOptions": { - "target": "ES2017", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, + "target": "ES2022", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", "skipLibCheck": true, - "strict": true, - "noEmit": true, - "esModuleInterop": true, - "module": "esnext", "moduleResolution": "bundler", - "resolveJsonModule": true, + "allowImportingTsExtensions": true, "isolatedModules": true, - "jsx": "preserve", - "incremental": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, "noImplicitAny": false, - "paths": { - "@/*": ["./src/*"] - } + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] + "include": ["src", "vite.config.ts"] } diff --git a/examples/plasmic/vite.config.ts b/examples/plasmic/vite.config.ts new file mode 100644 index 0000000..cc60590 --- /dev/null +++ b/examples/plasmic/vite.config.ts @@ -0,0 +1,15 @@ +import { devServer } from "bknd/adapter/vite"; +import react from "@vitejs/plugin-react"; +import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [ + react(), + tsconfigPaths(), + devServer({ + entry: "./src/server.ts" + }) as any + ] +}); \ No newline at end of file diff --git a/packages/plasmic/package.json b/packages/plasmic/package.json index 8d128c5..3a31a01 100644 --- a/packages/plasmic/package.json +++ b/packages/plasmic/package.json @@ -1,6 +1,6 @@ { "name": "@bknd/plasmic", - "version": "0.3.4-alpha1", + "version": "0.5.0", "type": "module", "sideEffects": false, "scripts": { @@ -28,24 +28,24 @@ "react": ">=18", "react-dom": ">=18", "@plasmicapp/host": ">=1.0.0", - "@plasmicapp/query": ">=0.1.0" + "@plasmicapp/loader-react": ">=1.0.0" }, "tsup": { "entry": [ "src/index.ts" ], - "minify": false, + "minify": true, "clean": true, "external": [ "react", "react-dom", "@plasmicapp/host", "@plasmicapp/query", + "@plasmicapp/loader-react", "swr" ], "format": [ - "esm", - "cjs" + "esm" ], "platform": "browser", "bundle": true, @@ -56,7 +56,7 @@ }, "types": "dist/index.d.ts", "module": "dist/index.js", - "main": "dist/index.cjs", + "main": "dist/index.js", "files": [ "dist", "README.md", diff --git a/packages/plasmic/src/components/Image.tsx b/packages/plasmic/src/components/Image.tsx index 9c50439..2ffb136 100644 --- a/packages/plasmic/src/components/Image.tsx +++ b/packages/plasmic/src/components/Image.tsx @@ -1,9 +1,7 @@ -import type { CodeComponentMeta } from "@plasmicapp/host"; -import registerComponent, { type ComponentMeta } from "@plasmicapp/host/registerComponent"; +import { type CodeComponentMeta, type ComponentMeta, registerComponent } from "@plasmicapp/host"; // biome-ignore lint/style/useImportType: import React from "react"; -//import { PlasmicCanvasContext } from "@plasmicapp/loader-react"; -import { useContext, useEffect, useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; type PlasmicImageProps = { asset: { diff --git a/packages/plasmic/src/components/LazyRender.tsx b/packages/plasmic/src/components/LazyRender.tsx index a49e3a3..d825ee4 100644 --- a/packages/plasmic/src/components/LazyRender.tsx +++ b/packages/plasmic/src/components/LazyRender.tsx @@ -1,5 +1,4 @@ -import type { CodeComponentMeta } from "@plasmicapp/host"; -import registerComponent, { type ComponentMeta } from "@plasmicapp/host/registerComponent"; +import { type CodeComponentMeta, type ComponentMeta, registerComponent } from "@plasmicapp/host"; // biome-ignore lint/style/useImportType: import React from "react"; import { useEffect, useRef, useState } from "react"; diff --git a/packages/plasmic/src/components/data/BkndData.tsx b/packages/plasmic/src/components/data/BkndData.tsx index 6f2068c..7f43334 100644 --- a/packages/plasmic/src/components/data/BkndData.tsx +++ b/packages/plasmic/src/components/data/BkndData.tsx @@ -1,6 +1,10 @@ -import { DataProvider, usePlasmicCanvasContext } from "@plasmicapp/host"; -import registerComponent, { type ComponentMeta } from "@plasmicapp/host/registerComponent"; -import { usePlasmicQueryData } from "@plasmicapp/query"; +import { + type ComponentMeta, + DataProvider, + registerComponent, + usePlasmicCanvasContext +} from "@plasmicapp/host"; +import { usePlasmicQueryData } from "@plasmicapp/loader-react"; import { useApi, useEntityQuery } from "bknd/client"; import type { RepoQuery } from "bknd/data"; // biome-ignore lint/style/useImportType: @@ -109,7 +113,7 @@ export function BkndData({ limit: entityId ? undefined : limit, offset: entityId ? undefined : offset, where: _where, - sort: { by: sortBy, dir: sortDir }, + sort: `${sortDir === "desc" ? "-" : ""}${sortBy}`, with: withRefs, join: joinRefs }; @@ -124,7 +128,7 @@ export function BkndData({ let references: string[] = []; if (entity && entity in entities) { - fields = Object.keys(entities[entity].fields!); + fields = Object.keys(entities[entity]?.fields ?? {}); if (relations) { const rels = Object.values(relations).filter( @@ -198,11 +202,11 @@ const ModeFetch = ({ return ; } - if (hasError) { + if (hasError || !data) { return ; } - if (data.length === 0) { + if (data?.length === 0) { return ; } @@ -248,6 +252,7 @@ export function registerBkndData( export const BkndDataMeta: ComponentMeta = { name: "BKND Data", + importName: "BkndData", section: "BKND", importPath: "@bknd/plasmic", providesData: true, @@ -264,6 +269,7 @@ export const BkndDataMeta: ComponentMeta = { }, select: { type: "choice", + multiSelect: true, options: (props, ctx) => ctx?.fields ?? [] }, limit: { diff --git a/packages/plasmic/src/contexts/BkndContext.tsx b/packages/plasmic/src/contexts/BkndContext.tsx index 7d32f6c..c87332b 100644 --- a/packages/plasmic/src/contexts/BkndContext.tsx +++ b/packages/plasmic/src/contexts/BkndContext.tsx @@ -1,7 +1,10 @@ -import { DataProvider, GlobalActionsProvider, usePlasmicCanvasContext } from "@plasmicapp/host"; -import registerGlobalContext, { - type GlobalContextMeta -} from "@plasmicapp/host/registerGlobalContext"; +import { + DataProvider, + GlobalActionsProvider, + type GlobalContextMeta, + registerGlobalContext, + usePlasmicCanvasContext +} from "@plasmicapp/host"; import type { AppConfig } from "bknd"; // @ts-ignore import { ClientProvider, useApi, useAuth, useBaseUrl } from "bknd/client"; @@ -24,7 +27,6 @@ type BkndContextProps = { const BkndContextContext = createContext({} as any); -// @todo: it's an issue that we need auth, so we cannot make baseurl adjustable (maybe add an option to useAuth with a specific base url?) export const BkndContext = ({ children, baseUrl, @@ -32,7 +34,7 @@ export const BkndContext = ({ }: React.PropsWithChildren) => { const auth = useAuth(); const baseurl = baseUrl ?? useBaseUrl(); - const api = useApi({ host: baseurl }); + const api = useApi(baseurl); const [data, setData] = useState({ baseUrl: baseurl, @@ -49,10 +51,6 @@ export const BkndContext = ({ (async () => { if (inEditor) { const result = await api.system.readConfig(); - - /*const res = await fetch(`${baseurl}/api/system/config`); - const result = (await res.json()) as BkndGlobalContextProps["appConfig"];*/ - console.log("appconfig", result); setData((prev) => ({ ...prev, appConfig: result })); } })(); @@ -60,41 +58,15 @@ export const BkndContext = ({ const actions = useMemo( () => ({ - login: async (data: any) => { - console.log("login", data); - const result = await auth.login(data); - console.log("login:result", result); - if (result.res.ok && "user" in result.data) { - //result.data. - return result.data; - } else { - console.log("login failed", result); - } - - return false; - }, - register: async (data: any) => { - console.log("register", data); - const result = await auth.register(data); - console.log("register:result", result); - if (result.res.ok && "user" in result.data) { - //result.data. - return result.data; - } - - return false; - }, - logout: async () => { - await auth.logout(); - console.log("logged out"); - return true; - }, + login: auth.login, + register: auth.register, + logout: auth.logout, setToken: auth.setToken }), [baseUrl] ); - console.log("plasmic.bknd.context", { baseUrl }); + console.log("plasmic.bknd.context", { baseurl }); return (