From f2fe5439f2d9569a8f34d46de810748954302bd4 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 3 Feb 2024 12:58:19 +0100 Subject: [PATCH] work on solidjs-auth --- archived_examples/with-authjs/app.config.ts | 3 ++ archived_examples/with-authjs/package.json | 27 ++++++------ .../with-authjs/src/{root.css => app.css} | 0 archived_examples/with-authjs/src/app.tsx | 24 +++++++++++ .../with-authjs/src/entry-client.tsx | 4 +- .../with-authjs/src/entry-server.tsx | 21 +++++++++- archived_examples/with-authjs/src/root.tsx | 42 ------------------- .../with-authjs/src/routes/[...404].tsx | 16 +------ .../src/routes/api/auth/[...solidauth].ts | 2 +- .../with-authjs/src/routes/index.tsx | 27 ++++++------ .../with-authjs/src/routes/protected.tsx | 22 +++++----- .../with-authjs/src/server/auth.ts | 3 +- archived_examples/with-authjs/vite.config.ts | 6 --- 13 files changed, 93 insertions(+), 104 deletions(-) create mode 100644 archived_examples/with-authjs/app.config.ts rename archived_examples/with-authjs/src/{root.css => app.css} (100%) create mode 100644 archived_examples/with-authjs/src/app.tsx delete mode 100644 archived_examples/with-authjs/src/root.tsx delete mode 100644 archived_examples/with-authjs/vite.config.ts diff --git a/archived_examples/with-authjs/app.config.ts b/archived_examples/with-authjs/app.config.ts new file mode 100644 index 000000000..de7f83103 --- /dev/null +++ b/archived_examples/with-authjs/app.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from "@solidjs/start/config"; + +export default defineConfig({}); diff --git a/archived_examples/with-authjs/package.json b/archived_examples/with-authjs/package.json index 5f0e09a3d..34d153827 100644 --- a/archived_examples/with-authjs/package.json +++ b/archived_examples/with-authjs/package.json @@ -1,27 +1,30 @@ { "name": "example-with-authjs", "scripts": { - "dev": "solid-start dev", - "build": "solid-start build", - "start": "solid-start start" + "dev": "vinxi dev", + "build": "vinxi build", + "start": "vinxi start" }, "type": "module", "devDependencies": { + "@types/babel__core": "7.20.0", "@types/node": "^18.17.5", "esbuild": "^0.14.54", "next-auth": "^4.23.1", "postcss": "^8.4.28", - "solid-start-node": "^0.3.10", - "typescript": "^4.9.5", - "vite": "^4.4.9" + "typescript": "^5.3.3", + "vite": "^5.1.4" }, "dependencies": { - "@auth/core": "^0.5.1", - "@solid-auth/base": "^2.0.3", - "@solidjs/meta": "^0.29.2", - "@solidjs/router": "^0.8.3", - "solid-js": "^1.8.6", - "solid-start": "^0.3.10" + "@auth/core": "^0.15.0", + "@babel/core": "7.20.12", + "@solid-mediakit/auth": "^2.0.1", + "@solid-mediakit/shared": "^0.0.3", + "@solidjs/meta": "^0.29.3", + "@solidjs/router": "^0.12.4", + "@solidjs/start": "^0.6.0", + "solid-js": "^1.8.15", + "vinxi": "^0.3.4" }, "engines": { "node": ">=18" diff --git a/archived_examples/with-authjs/src/root.css b/archived_examples/with-authjs/src/app.css similarity index 100% rename from archived_examples/with-authjs/src/root.css rename to archived_examples/with-authjs/src/app.css diff --git a/archived_examples/with-authjs/src/app.tsx b/archived_examples/with-authjs/src/app.tsx new file mode 100644 index 000000000..bfcfff186 --- /dev/null +++ b/archived_examples/with-authjs/src/app.tsx @@ -0,0 +1,24 @@ +// @refresh reload +import { MetaProvider, Title } from "@solidjs/meta"; +import { Router } from "@solidjs/router"; +import { FileRoutes } from "@solidjs/start"; +import { Suspense } from "solid-js"; +import "./app.css"; + +export default function App() { + return ( + ( + + SolidStart - Basic + Index + Protected + {props.children} + + )} + > + + + ); +} + diff --git a/archived_examples/with-authjs/src/entry-client.tsx b/archived_examples/with-authjs/src/entry-client.tsx index 942284855..e10a0fd99 100644 --- a/archived_examples/with-authjs/src/entry-client.tsx +++ b/archived_examples/with-authjs/src/entry-client.tsx @@ -1,3 +1,3 @@ -import { mount, StartClient } from "solid-start/entry-client"; +import { mount, StartClient } from "@solidjs/start/client"; -mount(() => , document); +mount(() => , document.getElementById("app")); diff --git a/archived_examples/with-authjs/src/entry-server.tsx b/archived_examples/with-authjs/src/entry-server.tsx index e5cf9c2c7..407a2afa1 100644 --- a/archived_examples/with-authjs/src/entry-server.tsx +++ b/archived_examples/with-authjs/src/entry-server.tsx @@ -1,3 +1,20 @@ -import { createHandler, renderAsync, StartServer } from "solid-start/entry-server"; +import { createHandler, StartServer } from "@solidjs/start/server"; -export default createHandler(renderAsync(event => )); +export default createHandler(() => ( + ( + + + + + + {assets} + + +
{children}
+ {scripts} + + + )} + /> +)); diff --git a/archived_examples/with-authjs/src/root.tsx b/archived_examples/with-authjs/src/root.tsx deleted file mode 100644 index e9350b851..000000000 --- a/archived_examples/with-authjs/src/root.tsx +++ /dev/null @@ -1,42 +0,0 @@ -// @refresh reload -import { SessionProvider } from "@solid-auth/base/client"; -import { Suspense } from "solid-js"; -import { - A, - Body, - ErrorBoundary, - FileRoutes, - Head, - Html, - Meta, - Routes, - Scripts, - Title -} from "solid-start"; -import "./root.css"; - -export default function Root() { - return ( - - - SolidStart + AuthJS - - - - - - - - Home - Protected - - - - - - - - - - ); -} diff --git a/archived_examples/with-authjs/src/routes/[...404].tsx b/archived_examples/with-authjs/src/routes/[...404].tsx index 108946012..60b0dd6da 100644 --- a/archived_examples/with-authjs/src/routes/[...404].tsx +++ b/archived_examples/with-authjs/src/routes/[...404].tsx @@ -1,19 +1,7 @@ -import { Title } from "solid-start"; -import { HttpStatusCode } from "solid-start/server"; - export default function NotFound() { return ( -
- Not Found - -

Page Not Found

-

- Visit{" "} - - start.solidjs.com - {" "} - to learn how to build SolidStart apps. -

+
+

Page Not Found

); } diff --git a/archived_examples/with-authjs/src/routes/api/auth/[...solidauth].ts b/archived_examples/with-authjs/src/routes/api/auth/[...solidauth].ts index 435732d4a..4385d7baa 100644 --- a/archived_examples/with-authjs/src/routes/api/auth/[...solidauth].ts +++ b/archived_examples/with-authjs/src/routes/api/auth/[...solidauth].ts @@ -1,4 +1,4 @@ -import { SolidAuth } from "@solid-auth/base"; +import { SolidAuth } from "@solid-mediakit/auth"; import { authOptions } from "~/server/auth"; export const { GET, POST } = SolidAuth(authOptions); diff --git a/archived_examples/with-authjs/src/routes/index.tsx b/archived_examples/with-authjs/src/routes/index.tsx index 62575cc51..c48a0bfcf 100644 --- a/archived_examples/with-authjs/src/routes/index.tsx +++ b/archived_examples/with-authjs/src/routes/index.tsx @@ -1,19 +1,20 @@ -import { getSession } from "@solid-auth/base"; -import { signIn } from "@solid-auth/base/client"; -import { createSignal, onCleanup, Show } from "solid-js"; -import { Navigate, useRouteData } from "solid-start"; -import { createServerData$ } from "solid-start/server"; +import { getSession } from "@solid-mediakit/auth"; +import { signIn } from "@solid-mediakit/auth/client"; +import { Navigate, createAsync } from "@solidjs/router"; +import { Show, createSignal, onCleanup } from "solid-js"; +import { getRequestEvent } from "solid-js/web"; import { authOptions } from "~/server/auth"; -export const routeData = () => { - return createServerData$(async (_, event) => { - const session = await getSession(event.request, authOptions); - return { session: session }; - }); -}; export default function Home() { - const session = useRouteData(); + const session = createAsync(async () => { + "use server"; + const event = getRequestEvent(); + const session = await getSession(event!.request, authOptions); + return session; + }); + + const [redirectIn, setRedirectIn] = createSignal(3); const int = setInterval(() => { @@ -26,7 +27,7 @@ export default function Home() {

Home

You are not signed in. diff --git a/archived_examples/with-authjs/src/routes/protected.tsx b/archived_examples/with-authjs/src/routes/protected.tsx index 43e9958b5..dc0e3449b 100644 --- a/archived_examples/with-authjs/src/routes/protected.tsx +++ b/archived_examples/with-authjs/src/routes/protected.tsx @@ -1,22 +1,24 @@ -import { getSession } from "@solid-auth/base"; -import { signOut } from "@solid-auth/base/client"; +import { getSession } from "@solid-mediakit/auth"; +import { signOut } from "@solid-mediakit/auth/client"; +import { createAsync, redirect } from "@solidjs/router"; import { Show, type VoidComponent } from "solid-js"; -import { useRouteData } from "solid-start"; -import { createServerData$, redirect } from "solid-start/server"; +import { getRequestEvent } from "solid-js/web"; import { authOptions } from "~/server/auth"; -export const routeData = () => { - return createServerData$(async (_, event) => { - const session = await getSession(event.request, authOptions); + +const Protected: VoidComponent = () => { + const session = createAsync(async () => { + "use server"; + const event = getRequestEvent(); + const session = await getSession(event!.request, authOptions); if (!session) { throw redirect("/"); } return session; }); -}; -const Protected: VoidComponent = () => { - const session = useRouteData(); + + return ( {us => ( diff --git a/archived_examples/with-authjs/src/server/auth.ts b/archived_examples/with-authjs/src/server/auth.ts index 485b4d18a..60d599f71 100644 --- a/archived_examples/with-authjs/src/server/auth.ts +++ b/archived_examples/with-authjs/src/server/auth.ts @@ -1,9 +1,8 @@ import DiscordProvider from "@auth/core/providers/discord"; -import type { SolidAuthConfig } from "@solid-auth/base"; +import type { SolidAuthConfig } from "@solid-mediakit/auth/src/index"; export const authOptions: SolidAuthConfig = { providers: [ - // @ts-expect-error Types are wrong DiscordProvider({ clientId: process.env.DISCORD_CLIENT_ID as string, clientSecret: process.env.DISCORD_CLIENT_SECRET as string diff --git a/archived_examples/with-authjs/vite.config.ts b/archived_examples/with-authjs/vite.config.ts deleted file mode 100644 index a1a712626..000000000 --- a/archived_examples/with-authjs/vite.config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import solid from "solid-start/vite"; -import { defineConfig } from "vite"; - -export default defineConfig({ - plugins: [solid()] -});