Date: Fri, 24 May 2024 17:58:34 +0300
Subject: [PATCH 6/7] upgrade solidstart example
---
package.json | 3 +++
solidstart/username-and-password/package.json | 20 +++++++++----------
solidstart/username-and-password/src/app.tsx | 2 +-
.../src/entry-server.tsx | 2 ++
.../username-and-password/src/lib/utils.ts | 4 ++--
.../src/routes/index.tsx | 16 +++++++++------
.../src/routes/login.tsx | 11 ++++++----
.../src/routes/signup.tsx | 8 +++++---
8 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/package.json b/package.json
index 6309fb7..7776eb9 100644
--- a/package.json
+++ b/package.json
@@ -13,5 +13,8 @@
"prettier": "^3.0.3",
"prettier-plugin-astro": "^0.12.0",
"prettier-plugin-svelte": "^3.0.3"
+ },
+ "dependencies": {
+ "typescript": "^5.4.5"
}
}
diff --git a/solidstart/username-and-password/package.json b/solidstart/username-and-password/package.json
index 3a2259e..748b860 100644
--- a/solidstart/username-and-password/package.json
+++ b/solidstart/username-and-password/package.json
@@ -7,19 +7,17 @@
"start": "node ./.output/server/index.mjs"
},
"dependencies": {
- "@lucia-auth/adapter-sqlite": "^3.0.0",
- "@solidjs/router": "^0.10.5",
- "@solidjs/start": "^0.4.2",
- "better-sqlite3": "^9.2.2",
- "lucia": "^3.0.1",
- "oslo": "^1.0.3",
- "solid-js": "^1.8.7",
- "vinxi": "0.0.54"
+ "@lucia-auth/adapter-sqlite": "^3.0.1",
+ "@solidjs/router": "^0.13.3",
+ "@solidjs/start": "^1.0.0",
+ "@types/better-sqlite3": "^7.6.10",
+ "better-sqlite3": "^9.4.3",
+ "lucia": "^3.2.0",
+ "oslo": "^1.2.0",
+ "solid-js": "^1.8.17",
+ "vinxi": "0.3.11"
},
"engines": {
"node": ">=18"
- },
- "devDependencies": {
- "@types/better-sqlite3": "^7.6.8"
}
}
diff --git a/solidstart/username-and-password/src/app.tsx b/solidstart/username-and-password/src/app.tsx
index 9648928..e6770ce 100644
--- a/solidstart/username-and-password/src/app.tsx
+++ b/solidstart/username-and-password/src/app.tsx
@@ -1,5 +1,5 @@
import { Router } from "@solidjs/router";
-import { FileRoutes } from "@solidjs/start";
+import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
export default function App() {
diff --git a/solidstart/username-and-password/src/entry-server.tsx b/solidstart/username-and-password/src/entry-server.tsx
index b1bbd6f..ff30c86 100644
--- a/solidstart/username-and-password/src/entry-server.tsx
+++ b/solidstart/username-and-password/src/entry-server.tsx
@@ -1,3 +1,5 @@
+// @refresh reload
+
import { createHandler, StartServer } from "@solidjs/start/server";
export default createHandler(() => (
diff --git a/solidstart/username-and-password/src/lib/utils.ts b/solidstart/username-and-password/src/lib/utils.ts
index 2404ca9..65a06b0 100644
--- a/solidstart/username-and-password/src/lib/utils.ts
+++ b/solidstart/username-and-password/src/lib/utils.ts
@@ -4,8 +4,8 @@ import { getRequestEvent } from "solid-js/web";
export const getAuthenticatedUser = cache(async () => {
"use server";
const event = getRequestEvent()!;
- if (!event.context.user) {
+ if (!event.locals.user) {
throw redirect("/login");
}
- return event.context.user;
+ return event.locals.user;
}, "user");
diff --git a/solidstart/username-and-password/src/routes/index.tsx b/solidstart/username-and-password/src/routes/index.tsx
index 2a910d9..4b299f6 100644
--- a/solidstart/username-and-password/src/routes/index.tsx
+++ b/solidstart/username-and-password/src/routes/index.tsx
@@ -1,14 +1,14 @@
import { action, createAsync, redirect } from "@solidjs/router";
import { getRequestEvent } from "solid-js/web";
-import { appendHeader } from "@solidjs/start/server";
+import { setCookie } from "vinxi/http";
import { lucia } from "~/lib/auth";
import { getAuthenticatedUser } from "~/lib/utils";
export default function Index() {
- const user = createAsync(getAuthenticatedUser);
+ const user = createAsync(() => getAuthenticatedUser());
return (
<>
- Hi, {user()?.username}!
+ Hi, {user()?.username}
Your user ID is {user()?.id}.