Skip to content

Commit

Permalink
work on solidjs-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum committed Mar 11, 2024
1 parent 2170036 commit f2fe543
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 104 deletions.
3 changes: 3 additions & 0 deletions archived_examples/with-authjs/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({});
27 changes: 15 additions & 12 deletions archived_examples/with-authjs/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions archived_examples/with-authjs/src/app.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Router
root={props => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<a href="/">Index</a>
<a href="/protected">Protected</a>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}

4 changes: 2 additions & 2 deletions archived_examples/with-authjs/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mount, StartClient } from "solid-start/entry-client";
import { mount, StartClient } from "@solidjs/start/client";

mount(() => <StartClient />, document);
mount(() => <StartClient />, document.getElementById("app"));
21 changes: 19 additions & 2 deletions archived_examples/with-authjs/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -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 => <StartServer event={event} />));
export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
{assets}
</head>
<body>
<div id="app">{children}</div>
{scripts}
</body>
</html>
)}
/>
));
42 changes: 0 additions & 42 deletions archived_examples/with-authjs/src/root.tsx

This file was deleted.

16 changes: 2 additions & 14 deletions archived_examples/with-authjs/src/routes/[...404].tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { Title } from "solid-start";
import { HttpStatusCode } from "solid-start/server";

export default function NotFound() {
return (
<main>
<Title>Not Found</Title>
<HttpStatusCode code={404} />
<h1>Page Not Found</h1>
<p>
Visit{" "}
<a href="https://start.solidjs.com" target="_blank">
start.solidjs.com
</a>{" "}
to learn how to build SolidStart apps.
</p>
<main class="w-full p-4 space-y-2">
<h1 class="font-bold text-xl">Page Not Found</h1>
</main>
);
}
Original file line number Diff line number Diff line change
@@ -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);
27 changes: 14 additions & 13 deletions archived_examples/with-authjs/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof routeData>();
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(() => {
Expand All @@ -26,7 +27,7 @@ export default function Home() {
<main>
<h1>Home</h1>
<Show
when={session()?.session}
when={session()}
fallback={
<>
<span>You are not signed in.</span>
Expand Down
22 changes: 12 additions & 10 deletions archived_examples/with-authjs/src/routes/protected.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof routeData>();


return (
<Show when={session()} keyed>
{us => (
Expand Down
3 changes: 1 addition & 2 deletions archived_examples/with-authjs/src/server/auth.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions archived_examples/with-authjs/vite.config.ts

This file was deleted.

0 comments on commit f2fe543

Please sign in to comment.