test(solid-start): basic-auth e2e suite and example #5558
Mergedbirkskyum(GitHub profile, opens in a new tab)merged 8 commits into
main fromrefs/pull/5558/headmerged by birkskyum(GitHub profile, opens in a new tab) - e2e/solid-start/basic-auth/.gitignore lines 5 to 10@@ -0,0 +1,10 @@1+node_modules2+package-lock.json3+yarn.lock4+5+!.env6+.DS_Store7+.cache8+.vercel9+.output10+e2e/solid-start/basic-auth/package.json line 12@@ -0,0 +1,12 @@1+{2+ "name": "tanstack-solid-start-e2e-basic-auth",3+ "private": true,4+ "sideEffects": false,5+ "type": "module",6+ "scripts": {7+ "dev": "vite dev --port 3000",8+ "dev:e2e": "vite dev",9+ "build": "vite build",10+ "start": "node .output/server/index.mjs",11+ "prisma-generate": "prisma generate",12+ "test:e2e": "exit 0; rm -rf port*.txt; pnpm run prisma-generate && playwright test --project=chromium"e2e/solid-start/basic-auth/package.json lines 16 to 19@@ -0,0 +1,19 @@1+{2+ "name": "tanstack-solid-start-e2e-basic-auth",3+ "private": true,4+ "sideEffects": false,5+ "type": "module",6+ "scripts": {7+ "dev": "vite dev --port 3000",8+ "dev:e2e": "vite dev",9+ "build": "vite build",10+ "start": "node .output/server/index.mjs",11+ "prisma-generate": "prisma generate",12+ "test:e2e": "exit 0; rm -rf port*.txt; pnpm run prisma-generate && playwright test --project=chromium"13+ },14+ "dependencies": {15+ "@prisma/client": "5.22.0",16+ "@tanstack/solid-router": "workspace:^",17+ "@tanstack/solid-router-devtools": "workspace:^",18+ "@tanstack/solid-start": "workspace:^",19+ "prisma": "^5.22.0",e2e/solid-start/basic-auth/prisma/migrations/20240811183753_init/migration.sql lines 7 to 8@@ -0,0 +1,8 @@1+-- CreateTable2+CREATE TABLE "User" (3+ "email" TEXT NOT NULL PRIMARY KEY,4+ "password" TEXT NOT NULL5+);6+7+-- CreateIndex8+CREATE UNIQUE INDEX "User_email_key" ON "User"("email");e2e/solid-start/basic-auth/src/components/Auth.tsx lines 10 to 12@@ -0,0 +1,12 @@1+import type { JSX } from 'solid-js'2+3+export function Auth({4+ actionText,5+ onSubmit,6+ status,7+ afterSubmit,8+}: {9+ actionText: string10+ onSubmit: (e: HTMLFormElement) => void11+ status: 'pending' | 'idle' | 'success' | 'error'12+ afterSubmit?: JSX.Elemente2e/solid-start/basic-auth/src/components/Login.tsx lines 11 to 20@@ -0,0 +1,20 @@1+import { useRouter } from '@tanstack/solid-router'2+import { useServerFn } from '@tanstack/solid-start'3+import { useMutation } from '../hooks/useMutation'4+import { loginFn } from '../routes/_authed'5+import { Auth } from './Auth'6+import { signupFn } from '~/routes/signup'7+8+export function Login() {9+ const router = useRouter()10+11+ const loginMutation = useMutation({12+ fn: loginFn,13+ onSuccess: async (ctx) => {14+ if (!ctx.data?.error) {15+ await router.invalidate()16+ router.navigate({ to: '/' })17+ return18+ }19+ },20+ })e2e/solid-start/basic-auth/src/components/Login.tsx lines 33 to 38@@ -0,0 +18,21 @@18+ }19+ },20+ })21+22+ const signupMutation = useMutation({23+ fn: useServerFn(signupFn),24+ })25+26+ return (27+ <Auth28+ actionText="Login"29+ status={loginMutation.status()}30+ onSubmit={(e) => {31+ const formData = new FormData(e.target as unknown as HTMLFormElement)32+33+ loginMutation.mutate({34+ data: {35+ email: formData.get('email') as string,36+ password: formData.get('password') as string,37+ },38+ })e2e/solid-start/basic-auth/src/components/Login.tsx lines 53 to 58@@ -0,0 +38,21 @@38+ })39+ }}40+ afterSubmit={41+ loginMutation.data() ? (42+ <>43+ <div class="text-red-400">{loginMutation.data()?.message}</div>44+ {loginMutation.data()?.userNotFound ? (45+ <div>46+ <button47+ class="text-blue-500"48+ onClick={(e) => {49+ const formData = new FormData(50+ (e.target as HTMLButtonElement).form!,51+ )52+53+ signupMutation.mutate({54+ data: {55+ email: formData.get('email') as string,56+ password: formData.get('password') as string,57+ },58+ })e2e/solid-start/basic-auth/src/routes/__root.tsx lines 101 to 108@@ -0,0 +88,21 @@88+})89+90+function RootComponent() {91+ return (92+ <RootDocument>93+ <Outlet />94+ </RootDocument>95+ )96+}97+98+function RootDocument({ children }: { children: Solid.JSX.Element }) {99+ const routeContext = Route.useRouteContext()100+101+ return (102+ <html>103+ <head>104+ <HydrationScript />105+ </head>106+ <body>107+ <HeadContent />108+ <div class="p-2 flex gap-2 text-lg">e2e/solid-start/basic-auth/src/routes/_authed/posts.tsx lines 16 to 21@@ -0,0 +1,21 @@1+import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'2+3+import { fetchPosts } from '~/utils/posts.js'4+5+function PostsComponent() {6+ const posts = Route.useLoaderData()7+8+ return (9+ <div class="p-2 flex gap-2">10+ <ul class="list-disc pl-4">11+ {[...posts(), { id: 'i-do-not-exist', title: 'Non-existent Post' }].map(12+ (post) => {13+ return (14+ <li class="whitespace-nowrap">15+ <Link16+ to="/posts/$postId"17+ params={{18+ postId: post.id,19+ }}20+ class="block py-1 text-blue-800 hover:text-blue-600"21+ activeProps={{ class: 'text-black font-bold' }}e2e/solid-start/basic-auth/src/routes/signup.tsx lines 84 to 89@@ -0,0 +69,21 @@69+ component: SignupComp,70+})71+72+function SignupComp() {73+ const signupMutation = useMutation({74+ fn: useServerFn(signupFn),75+ })76+77+ return (78+ <Auth79+ actionText="Sign Up"80+ status={signupMutation.status()}81+ onSubmit={(e) => {82+ const formData = new FormData(e.target as any as HTMLFormElement)83+84+ signupMutation.mutate({85+ data: {86+ email: formData.get('email') as string,87+ password: formData.get('password') as string,88+ },89+ })e2e/solid-start/basic-auth/src/utils/posts.ts lines 5 to 37@@ -0,0 +17,21 @@17+ .then((r) => r.data)18+ .catch((err) => {19+ console.error(err)20+ if (err.status === 404) {21+ throw notFound()22+ }23+ throw err24+ })25+26+ return post27+ })28+29+export const fetchPosts = createServerFn({ method: 'GET' }).handler(30+ async () => {31+ console.info('Fetching posts...')32+ await new Promise((r) => setTimeout(r, 1000))33+ return axios34+ .get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')35+ .then((r) => r.data.slice(0, 10))36+ },37+)e2e/solid-start/basic-auth/src/utils/prisma.ts lines 6 to 16@@ -0,0 +1,16 @@1+import crypto from 'node:crypto'2+import { PrismaClient } from '@prisma/client'3+4+export const prismaClient = new PrismaClient()5+6+export function hashPassword(password: string) {7+ return new Promise<string>((resolve, reject) => {8+ crypto.pbkdf2(password, 'salt', 100000, 64, 'sha256', (err, derivedKey) => {9+ if (err) {10+ reject(err)11+ } else {12+ resolve(derivedKey.toString('hex'))13+ }14+ })15+ })16+}e2e/solid-start/basic-auth/src/utils/seo.ts lines 1 to 33@@ -0,0 +13,21 @@13+ { title },14+ { name: 'description', content: description },15+ { name: 'keywords', content: keywords },16+ { name: 'twitter:title', content: title },17+ { name: 'twitter:description', content: description },18+ { name: 'twitter:creator', content: '@tannerlinsley' },19+ { name: 'twitter:site', content: '@tannerlinsley' },20+ { name: 'og:type', content: 'website' },21+ { name: 'og:title', content: title },22+ { name: 'og:description', content: description },23+ ...(image24+ ? [25+ { name: 'twitter:image', content: image },26+ { name: 'twitter:card', content: 'summary_large_image' },27+ { name: 'og:image', content: image },28+ ]29+ : []),30+ ]31+32+ return tags33+}e2e/solid-start/basic-auth/src/utils/session.ts lines 1 to 2@@ -0,0 +1,2 @@1+// src/services/session.server.ts2+import { useSession } from '@tanstack/solid-start/server'e2e/solid-start/basic-auth/src/utils/session.ts lines 3 to 12@@ -0,0 +1,12 @@1+// src/services/session.server.ts2+import { useSession } from '@tanstack/solid-start/server'3+import type { User } from '@prisma/client'4+5+type SessionUser = {6+ userEmail: User['email']7+}8+9+export function useAppSession() {10+ return useSession<SessionUser>({11+ password: 'ChangeThisBeforeShippingToProdOrYouWillBeFired',12+ })e2e/solid-start/basic-auth/tests/app.spec.ts lines 4 to 14@@ -0,0 +1,14 @@1+import { expect, test } from '@playwright/test'2+import type { Page } from '@playwright/test'3+4+async function signup(5+ page: Page,6+ baseUrl: string,7+ email: string,8+ password: string,9+) {10+ await page.goto(baseUrl + '/signup')11+ await page.fill('input[name="email"]', email)12+ await page.fill('input[name="password"]', password)13+ await page.click('button[type="submit"]')14+}e2e/solid-start/basic-auth/tests/app.spec.ts lines 39 to 42@@ -0,0 +22,21 @@22+ await page.goto('/login')23+ await page.fill('input[name="email"]', email)24+ await page.fill('input[name="password"]', password)25+ await page.click('button[type="submit"]')26+27+ if (signupOnFail) {28+ await page.waitForSelector('text=User not found')29+ await page.click('button:has-text("Sign up instead?")')30+ await page.waitForSelector('text=Logout')31+ }32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})e2e/solid-start/basic-auth/tests/app.spec.ts lines 44 to 47@@ -0,0 +27,21 @@27+ if (signupOnFail) {28+ await page.waitForSelector('text=User not found')29+ await page.click('button:has-text("Sign up instead?")')30+ await page.waitForSelector('text=Logout')31+ }32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})e2e/solid-start/basic-auth/tests/app.spec.ts lines 49 to 52@@ -0,0 +32,21 @@32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})48+49+test('Can sign up from a not found user', async ({ page }) => {50+ await login(page, 'test2@gmail.com', 'badpassword', true)51+ expect(page.getByText('test@gmail.com')).toBeTruthy()52+})e2e/solid-start/basic-auth/tests/app.spec.ts lines 54 to 60@@ -0,0 +40,21 @@40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})48+49+test('Can sign up from a not found user', async ({ page }) => {50+ await login(page, 'test2@gmail.com', 'badpassword', true)51+ expect(page.getByText('test@gmail.com')).toBeTruthy()52+})53+54+test('Navigating to post after logging in', async ({ page }) => {55+ await login(page, 'test@gmail.com', 'test')56+ await new Promise((r) => setTimeout(r, 1000))57+ await page.getByRole('link', { name: 'Posts' }).click()58+ await page.getByRole('link', { name: 'sunt aut facere repe' }).click()59+ await expect(page.getByRole('heading')).toContainText('sunt aut facere')60+})e2e/solid-start/basic-auth/tests/mock-db-teardown.test.ts line 7@@ -0,0 +1,7 @@1+import { test as teardown } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+teardown('create new database', async () => {e2e/solid-start/serialization-adapters/test-results/.last-run.json lines 1 to 10Outdated@@ -0,0 +1,10 @@1+{2+ "status": "failed",3+ "failedTests": [4+ "c31ff144dc4fee3acd0a-a3f4261a6950352c3412",5+ "c31ff144dc4fee3acd0a-5813a6fc1d3422ca81e6",6+ "c31ff144dc4fee3acd0a-10a9860bf9da922f3c88",7+ "c31ff144dc4fee3acd0a-7ac8fe622cee8b733158",8+ "c31ff144dc4fee3acd0a-ab3c0665de5c45cec0b3"9+ ]10+}e2e/solid-start/serialization-adapters/test-results/app-server-functions-serialization-adapters-custom-error-chromium/error-context.md lines 1 to 15Outdated@@ -0,0 +1,15 @@1+# Test info2+3+Name: server functions serialization adapters >> custom error4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:80:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/server-function/custom-error10+Call log:11+navigating to "http://localhost:49955/server-function/custom-error", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:81:1614+```15+e2e/solid-start/serialization-adapters/test-results/app-server-functions-serialization-adapters-custom-error-chromium/error-context.md lines 8 to 14Outdated@@ -0,0 +1,14 @@1+# Test info2+3+Name: server functions serialization adapters >> custom error4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:80:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/server-function/custom-error10+Call log:11+navigating to "http://localhost:49955/server-function/custom-error", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:81:1614+```e2e/solid-start/serialization-adapters/test-results/app-server-functions-serialization-adapters-nested-chromium/error-context.md lines 1 to 15Outdated@@ -0,0 +1,15 @@1+# Test info2+3+Name: server functions serialization adapters >> nested4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:101:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/server-function/nested10+Call log:11+navigating to "http://localhost:49955/server-function/nested", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:102:1614+```15+e2e/solid-start/serialization-adapters/test-results/app-server-functions-serialization-adapters-nested-chromium/error-context.md lines 8 to 14Outdated@@ -0,0 +1,14 @@1+# Test info2+3+Name: server functions serialization adapters >> nested4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:101:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/server-function/nested10+Call log:11+navigating to "http://localhost:49955/server-function/nested", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:102:1614+```e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-data-only-chromium/error-context.md lines 1 to 21Outdated@@ -0,0 +1,21 @@1+# Test info2+3+Name: SSR serialization adapters >> data-only4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:48:35+6+# Error details7+8+```9+Error: Timed out 5000ms waiting for expect(locator).toContainText(expected)10+11+Locator: getByTestId('router-isLoading')12+Expected string: "false"13+Received: <element(s) not found>14+Call log:15+expect.toContainText with timeout 5000ms16+waiting for getByTestId('router-isLoading')17+18+ at awaitPageLoaded (/Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:8:54)19+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:50:1120+```21+e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-data-only-chromium/error-context.md lines 8 to 20Outdated@@ -0,0 +1,20 @@1+# Test info2+3+Name: SSR serialization adapters >> data-only4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:48:35+6+# Error details7+8+```9+Error: Timed out 5000ms waiting for expect(locator).toContainText(expected)10+11+Locator: getByTestId('router-isLoading')12+Expected string: "false"13+Received: <element(s) not found>14+Call log:15+expect.toContainText with timeout 5000ms16+waiting for getByTestId('router-isLoading')17+18+ at awaitPageLoaded (/Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:8:54)19+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:50:1120+```e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-nested-chromium/error-context.md lines 1 to 15Outdated@@ -0,0 +1,15 @@1+# Test info2+3+Name: SSR serialization adapters >> nested4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:71:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/ssr/nested10+Call log:11+navigating to "http://localhost:49955/ssr/nested", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:72:1614+```15+e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-nested-chromium/error-context.md lines 8 to 14Outdated@@ -0,0 +1,14 @@1+# Test info2+3+Name: SSR serialization adapters >> nested4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:71:35+6+# Error details7+8+```9+Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:49955/ssr/nested10+Call log:11+navigating to "http://localhost:49955/ssr/nested", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:72:1614+```e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-stream-chromium/error-context-1.md lines 1 to 20Outdated@@ -0,0 +1,20 @@1+# Test info2+3+Name: SSR serialization adapters >> stream4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:65:35+6+# Error details7+8+```9+Error: expect(received).toEqual(expected) // deep equality10+11+Expected - 112+Received + 313+14+Array []15+Array [16+ "Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING",17+]18+ at Object.page (/Users/admin/repos/tanstack/router/e2e/e2e-utils/dist/esm/fixture.js:18:27)19+```20+e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-stream-chromium/error-context-1.md lines 8 to 19Outdated@@ -0,0 +1,19 @@1+# Test info2+3+Name: SSR serialization adapters >> stream4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:65:35+6+# Error details7+8+```9+Error: expect(received).toEqual(expected) // deep equality10+11+Expected - 112+Received + 313+14+Array []15+Array [16+ "Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING",17+]18+ at Object.page (/Users/admin/repos/tanstack/router/e2e/e2e-utils/dist/esm/fixture.js:18:27)19+```e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-stream-chromium/error-context-2.md lines 1 to 15Outdated@@ -0,0 +1,15 @@1+# Test info2+3+Name: SSR serialization adapters >> stream4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:65:35+6+# Error details7+8+```9+Error: page.goto: Test timeout of 30000ms exceeded.10+Call log:11+navigating to "http://localhost:49955/ssr/stream", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:66:1614+```15+e2e/solid-start/serialization-adapters/test-results/app-SSR-serialization-adapters-stream-chromium/error-context-2.md lines 8 to 14Outdated@@ -0,0 +1,14 @@1+# Test info2+3+Name: SSR serialization adapters >> stream4+Location: /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:65:35+6+# Error details7+8+```9+Error: page.goto: Test timeout of 30000ms exceeded.10+Call log:11+navigating to "http://localhost:49955/ssr/stream", waiting until "load"12+13+ at /Users/admin/repos/tanstack/router/e2e/solid-start/serialization-adapters/tests/app.spec.ts:66:1614+```
birkskyum(GitHub profile, opens in a new tab) changed the title
- e2e/solid-start/basic-auth/src/components/Login.tsx lines 31 to 39@@ -0,0 +19,21 @@19+ },20+ })21+22+ const signupMutation = useMutation({23+ fn: useServerFn(signupFn),24+ })25+26+ return (27+ <Auth28+ actionText="Login"29+ status={loginMutation.status()}30+ onSubmit={(e) => {31+ const formData = new FormData(e.target as unknown as HTMLFormElement)32+33+ loginMutation.mutate({34+ data: {35+ email: formData.get('email') as string,36+ password: formData.get('password') as string,37+ },38+ })39+ }}e2e/solid-start/basic-auth/src/routes/_authed.tsx lines 20 to 27Outdated@@ -0,0 +7,21 @@7+8+export const loginFn = createServerFn({9+ method: 'POST',10+})11+ .inputValidator((payload: { email: string; password: string }) => payload)12+ .handler(async ({ data }) => {13+ // Find the user14+ const user = await prismaClient.user.findUnique({15+ where: {16+ email: data.email,17+ },18+ })19+20+ // Check if the user exists21+ if (!user) {22+ return {23+ error: true,24+ userNotFound: true,25+ message: 'User not found',26+ }27+ }e2e/solid-start/basic-auth/src/routes/_authed.tsx lines 29 to 36Outdated@@ -0,0 +16,21 @@16+ email: data.email,17+ },18+ })19+20+ // Check if the user exists21+ if (!user) {22+ return {23+ error: true,24+ userNotFound: true,25+ message: 'User not found',26+ }27+ }28+29+ // Check if the password is correct30+ const hashedPassword = await hashPassword(data.password)31+32+ if (user.password !== hashedPassword) {33+ return {34+ error: true,35+ message: 'Incorrect password',36+ }e2e/solid-start/basic-auth/src/routes/_authed/posts.$postId.tsx line 12Outdated@@ -0,0 +1,12 @@1+import { ErrorComponent, createFileRoute } from '@tanstack/solid-router'2+import type { ErrorComponentProps } from '@tanstack/solid-router'3+4+import { NotFound } from '~/components/NotFound.js'5+import { fetchPost } from '~/utils/posts.js'6+7+export function PostErrorComponent({ error }: ErrorComponentProps) {8+ return <ErrorComponent error={error} />9+}10+11+export const Route = createFileRoute('/_authed/posts/$postId')({12+ loader: ({ params: { postId } }) => fetchPost({ data: postId }),e2e/solid-start/basic-auth/src/routes/signup.tsx line 23@@ -0,0 +3,21 @@3+4+import { hashPassword, prismaClient } from '~/utils/prisma'5+import { useMutation } from '~/hooks/useMutation'6+import { Auth } from '~/components/Auth'7+import { useAppSession } from '~/utils/session'8+9+export const signupFn = createServerFn({10+ method: 'POST',11+})12+ .inputValidator(13+ (data: { email: string; password: string; redirectUrl?: string }) => data,14+ )15+ .handler(async ({ data: payload }) => {16+ // Check if the user already exists17+ const found = await prismaClient.user.findUnique({18+ where: {19+ email: payload.email,20+ },21+ })22+23+ // Encrypt the password using Sha256 into plaintexte2e/solid-start/basic-auth/src/routes/signup.tsx lines 29 to 36@@ -0,0 +16,21 @@16+ // Check if the user already exists17+ const found = await prismaClient.user.findUnique({18+ where: {19+ email: payload.email,20+ },21+ })22+23+ // Encrypt the password using Sha256 into plaintext24+ const password = await hashPassword(payload.password)25+26+ // Create a session27+ const session = await useAppSession()28+29+ if (found) {30+ if (found.password !== password) {31+ return {32+ error: true,33+ userExists: true,34+ message: 'User already exists',35+ }36+ }e2e/solid-start/basic-auth/tests/mock-db-setup.test.ts line 5Outdated@@ -0,0 +1,5 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()e2e/solid-start/basic-auth/tests/mock-db-setup.test.ts lines 7 to 21Outdated@@ -0,0 +1,21 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+setup('create new database', async () => {8+ if (9+ await prismaClient.user.findUnique({10+ where: {11+ email: 'test2@gmail.com',12+ },13+ })14+ ) {15+ await prismaClient.user.delete({16+ where: {17+ email: 'test2@gmail.com',18+ },19+ })20+ }21+})examples/react/start-basic-auth/package.json line 12Outdated@@ -1,10 +1,12 @@11 {2- "name": "tanstack-start-example-basic-auth",2+ "name": "tanstack-react-start-e2e-basic-auth",33 "private": true,44 "sideEffects": false,55 "type": "module",66 "scripts": {7- "dev": "vite dev",7+ "dev": "vite dev --port 3000",8+ "dev:e2e": "vite dev",89 "build": "vite build",9- "start": "vite start",10- "prisma-generate": "prisma generate"10+ "start": "node .output/server/index.mjs",11+ "prisma-generate": "prisma generate",12+ "test:e2e": "exit 0; rm -rf port*.txt; pnpm run prisma-generate && playwright test --project=chromium"examples/react/start-basic-auth/tests/app.spec.ts lines 4 to 14Outdated@@ -0,0 +1,14 @@1+import { expect, test } from '@playwright/test'2+import type { Page } from '@playwright/test'3+4+async function signup(5+ page: Page,6+ baseUrl: string,7+ email: string,8+ password: string,9+) {10+ await page.goto(baseUrl + '/signup')11+ await page.fill('input[name="email"]', email)12+ await page.fill('input[name="password"]', password)13+ await page.click('button[type="submit"]')14+}examples/react/start-basic-auth/tests/app.spec.ts lines 44 to 47Outdated@@ -0,0 +27,21 @@27+ if (signupOnFail) {28+ await page.waitForSelector('text=User not found')29+ await page.click('button:has-text("Sign up instead?")')30+ await page.waitForSelector('text=Logout')31+ }32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})examples/react/start-basic-auth/tests/mock-db-setup.test.ts line 5Outdated@@ -0,0 +1,5 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()examples/react/start-basic-auth/tests/mock-db-setup.test.ts line 7Outdated@@ -0,0 +1,7 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+setup('create new database', async () => {examples/react/start-basic-auth/tests/mock-db-teardown.test.ts line 5Outdated@@ -0,0 +1,5 @@1+import { test as teardown } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()examples/react/start-basic-auth/tests/mock-db-teardown.test.ts line 7Outdated@@ -0,0 +1,7 @@1+import { test as teardown } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+teardown('create new database', async () => {examples/solid/start-basic-auth/package.json lines 16 to 18Outdated@@ -0,0 +1,18 @@1+{2+ "name": "tanstack-solid-start-e2e-basic-auth",3+ "private": true,4+ "sideEffects": false,5+ "type": "module",6+ "scripts": {7+ "dev": "vite dev --port 3000",8+ "dev:e2e": "vite dev",9+ "build": "vite build",10+ "start": "node .output/server/index.mjs",11+ "prisma-generate": "prisma generate",12+ "test:e2e": "exit 0; rm -rf port*.txt; pnpm run prisma-generate && playwright test --project=chromium"13+ },14+ "dependencies": {15+ "@prisma/client": "5.22.0",16+ "@tanstack/solid-router": "workspace:^",17+ "@tanstack/solid-router-devtools": "workspace:^",18+ "@tanstack/solid-start": "workspace:^",examples/solid/start-basic-auth/prisma/migrations/20240811183753_init/migration.sql lines 1 to 8Outdated@@ -0,0 +1,8 @@1+-- CreateTable2+CREATE TABLE "User" (3+ "email" TEXT NOT NULL PRIMARY KEY,4+ "password" TEXT NOT NULL5+);6+7+-- CreateIndex8+CREATE UNIQUE INDEX "User_email_key" ON "User"("email");examples/solid/start-basic-auth/prisma/schema.prisma line 14Outdated@@ -0,0 +1,14 @@1+// This is your Prisma schema file,2+// learn more about it in the docs: https://pris.ly/d/prisma-schema3+4+generator client {5+ provider = "prisma-client-js"6+}7+8+datasource db {9+ provider = "sqlite"10+ url = env("DATABASE_URL")11+}12+13+model User {14+ email String @id @uniqueexamples/solid/start-basic-auth/src/components/Auth.tsx lines 18 to 22Outdated@@ -0,0 +2,21 @@2+3+export function Auth({4+ actionText,5+ onSubmit,6+ status,7+ afterSubmit,8+}: {9+ actionText: string10+ onSubmit: (e: HTMLFormElement) => void11+ status: 'pending' | 'idle' | 'success' | 'error'12+ afterSubmit?: JSX.Element13+}) {14+ return (15+ <div class="fixed inset-0 bg-white dark:bg-black flex items-start justify-center p-8">16+ <div class="bg-white dark:bg-gray-900 p-8 rounded-lg shadow-lg">17+ <h1 class="text-2xl font-bold mb-4">{actionText}</h1>18+ <form19+ onSubmit={(e: any) => {20+ e.preventDefault()21+ onSubmit(e)22+ }}examples/solid/start-basic-auth/src/components/Login.tsx lines 53 to 58Outdated@@ -0,0 +38,21 @@38+ })39+ }}40+ afterSubmit={41+ loginMutation.data() ? (42+ <>43+ <div class="text-red-400">{loginMutation.data()?.message}</div>44+ {loginMutation.data()?.userNotFound ? (45+ <div>46+ <button47+ class="text-blue-500"48+ onClick={(e) => {49+ const formData = new FormData(50+ (e.target as HTMLButtonElement).form!,51+ )52+53+ signupMutation.mutate({54+ data: {55+ email: formData.get('email') as string,56+ password: formData.get('password') as string,57+ },58+ })examples/solid/start-basic-auth/src/routes/__root.tsx lines 19 to 29Outdated@@ -0,0 +11,21 @@11+12+import { HydrationScript } from 'solid-js/web'13+import type { JSX } from 'solid-js'14+15+import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary.js'16+import { NotFound } from '~/components/NotFound.js'17+import appCss from '~/styles/app.css?url'18+import { seo } from '~/utils/seo.js'19+import { useAppSession } from '~/utils/session.js'20+21+const fetchUser = createServerFn({ method: 'GET' }).handler(async () => {22+ // We need to auth on the server so we have access to secure cookies23+ const session = await useAppSession()24+25+ if (!session.data.userEmail) {26+ return null27+ }28+29+ return {30+ email: session.data.userEmail,31+ }examples/solid/start-basic-auth/src/routes/__root.tsx lines 50 to 54Outdated@@ -0,0 +36,21 @@36+ const user = await fetchUser()37+38+ return {39+ user,40+ }41+ },42+ head: () => ({43+ meta: [44+ {45+ charset: 'utf-8',46+ },47+ {48+ name: 'viewport',49+ content: 'width=device-width, initial-scale=1',50+ },51+ ...seo({52+ title:53+ 'TanStack Start | Type-Safe, Client-First, Full-Stack React Framework',54+ description: `TanStack Start is a type-safe, client-first, full-stack React framework. `,55+ }),56+ ],examples/solid/start-basic-auth/src/routes/__root.tsx lines 74 to 77Outdated@@ -0,0 +59,21 @@59+ {60+ rel: 'apple-touch-icon',61+ sizes: '180x180',62+ href: '/apple-touch-icon.png',63+ },64+ {65+ rel: 'icon',66+ type: 'image/png',67+ sizes: '32x32',68+ href: '/favicon-32x32.png',69+ },70+ {71+ rel: 'icon',72+ type: 'image/png',73+ sizes: '16x16',74+ href: '/favicon-16x16.png',75+ },76+ { rel: 'manifest', href: '/site.webmanifest', color: '#fffff' },77+ { rel: 'icon', href: '/favicon.ico' },78+ ],79+ }),examples/solid/start-basic-auth/src/routes/_authed.tsx lines 8 to 46Outdated@@ -0,0 +26,21 @@26+ }27+ }28+29+ // Check if the password is correct30+ const hashedPassword = await hashPassword(data.password)31+32+ if (user.password !== hashedPassword) {33+ return {34+ error: true,35+ message: 'Incorrect password',36+ }37+ }38+39+ // Create a session40+ const session = await useAppSession()41+42+ // Store the user's email in the session43+ await session.update({44+ userEmail: user.email,45+ })46+ })examples/solid/start-basic-auth/src/routes/_authed.tsx lines 26 to 33Outdated@@ -0,0 +16,21 @@16+ email: data.email,17+ },18+ })19+20+ // Check if the user exists21+ if (!user) {22+ return {23+ error: true,24+ userNotFound: true,25+ message: 'User not found',26+ }27+ }28+29+ // Check if the password is correct30+ const hashedPassword = await hashPassword(data.password)31+32+ if (user.password !== hashedPassword) {33+ return {34+ error: true,35+ message: 'Incorrect password',36+ }@@ -0,0 +69,21 @@69+ component: SignupComp,70+})71+72+function SignupComp() {73+ const signupMutation = useMutation({74+ fn: useServerFn(signupFn),75+ })76+77+ return (78+ <Auth79+ actionText="Sign Up"80+ status={signupMutation.status()}81+ onSubmit={(e) => {82+ const formData = new FormData(e.target as any as HTMLFormElement)83+84+ signupMutation.mutate({85+ data: {86+ email: formData.get('email') as string,87+ password: formData.get('password') as string,88+ },89+ })examples/solid/start-basic-auth/src/styles/app.css lines 19 to 21Outdated@@ -0,0 +1,21 @@1+@tailwind base;2+@tailwind components;3+@tailwind utilities;4+5+@layer base {6+ html {7+ color-scheme: light dark;8+ }9+10+ * {11+ @apply border-gray-200 dark:border-gray-800;12+ }13+14+ html,15+ body {16+ @apply text-gray-900 bg-gray-50 dark:bg-gray-950 dark:text-gray-200;17+ }18+19+ .using-mouse * {20+ outline: none !important;21+ }examples/solid/start-basic-auth/src/utils/prisma.ts lines 6 to 16Outdated@@ -0,0 +1,16 @@1+import crypto from 'node:crypto'2+import { PrismaClient } from '@prisma/client'3+4+export const prismaClient = new PrismaClient()5+6+export function hashPassword(password: string) {7+ return new Promise<string>((resolve, reject) => {8+ crypto.pbkdf2(password, 'salt', 100000, 64, 'sha256', (err, derivedKey) => {9+ if (err) {10+ reject(err)11+ } else {12+ resolve(derivedKey.toString('hex'))13+ }14+ })15+ })16+}examples/solid/start-basic-auth/src/utils/seo.ts lines 12 to 30Outdated@@ -0,0 +10,21 @@10+ keywords?: string11+}) => {12+ const tags = [13+ { title },14+ { name: 'description', content: description },15+ { name: 'keywords', content: keywords },16+ { name: 'twitter:title', content: title },17+ { name: 'twitter:description', content: description },18+ { name: 'twitter:creator', content: '@tannerlinsley' },19+ { name: 'twitter:site', content: '@tannerlinsley' },20+ { name: 'og:type', content: 'website' },21+ { name: 'og:title', content: title },22+ { name: 'og:description', content: description },23+ ...(image24+ ? [25+ { name: 'twitter:image', content: image },26+ { name: 'twitter:card', content: 'summary_large_image' },27+ { name: 'og:image', content: image },28+ ]29+ : []),30+ ]examples/solid/start-basic-auth/tests/app.spec.ts lines 39 to 42Outdated@@ -0,0 +22,21 @@22+ await page.goto('/login')23+ await page.fill('input[name="email"]', email)24+ await page.fill('input[name="password"]', password)25+ await page.click('button[type="submit"]')26+27+ if (signupOnFail) {28+ await page.waitForSelector('text=User not found')29+ await page.click('button:has-text("Sign up instead?")')30+ await page.waitForSelector('text=Logout')31+ }32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})examples/solid/start-basic-auth/tests/app.spec.ts lines 44 to 47Outdated@@ -0,0 +27,21 @@27+ if (signupOnFail) {28+ await page.waitForSelector('text=User not found')29+ await page.click('button:has-text("Sign up instead?")')30+ await page.waitForSelector('text=Logout')31+ }32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})examples/solid/start-basic-auth/tests/app.spec.ts lines 49 to 52Outdated@@ -0,0 +32,21 @@32+}33+34+test('Posts redirects to login when not authenticated', async ({ page }) => {35+ await page.goto('/posts')36+ await expect(page.locator('h1')).toContainText('Login')37+})38+39+test('Login fails with user not found', async ({ page }) => {40+ await login(page, 'bad@gmail.com', 'badpassword')41+ expect(page.getByText('User not found')).toBeTruthy()42+})43+44+test('Login fails with incorrect password', async ({ page }) => {45+ await signup(page, 'test@gmail.com', 'badpassword')46+ expect(page.getByText('Incorrect password')).toBeTruthy()47+})48+49+test('Can sign up from a not found user', async ({ page }) => {50+ await login(page, 'test2@gmail.com', 'badpassword', true)51+ expect(page.getByText('test@gmail.com')).toBeTruthy()52+})examples/solid/start-basic-auth/tests/mock-db-setup.test.ts line 5Outdated@@ -0,0 +1,5 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()examples/solid/start-basic-auth/tests/mock-db-setup.test.ts lines 7 to 21Outdated@@ -0,0 +1,21 @@1+import { test as setup } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+setup('create new database', async () => {8+ if (9+ await prismaClient.user.findUnique({10+ where: {11+ email: 'test2@gmail.com',12+ },13+ })14+ ) {15+ await prismaClient.user.delete({16+ where: {17+ email: 'test2@gmail.com',18+ },19+ })20+ }21+})examples/solid/start-basic-auth/tests/mock-db-teardown.test.ts lines 5 to 21Outdated@@ -0,0 +1,21 @@1+import { test as teardown } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+teardown('create new database', async () => {8+ if (9+ await prismaClient.user.findUnique({10+ where: {11+ email: 'test2@gmail.com',12+ },13+ })14+ ) {15+ await prismaClient.user.delete({16+ where: {17+ email: 'test2@gmail.com',18+ },19+ })20+ }21+})examples/solid/start-basic-auth/tests/mock-db-teardown.test.ts line 7Outdated@@ -0,0 +1,7 @@1+import { test as teardown } from '@playwright/test'2+3+import { PrismaClient } from '@prisma/client'4+5+const prismaClient = new PrismaClient()6+7+teardown('create new database', async () => {
- examples/solid/start-basic-auth/README.md lines 1 to 72@@ -0,0 +52,21 @@52+ ```53+54+ [!WARNING]55+ Make sure the name of the directory in your local file system matches the name of the project's repo. For example, `tanstack/form` must be cloned into `form` (this is the default) instead of `some-other-name`, because that way, the doc pages won't be found.56+57+Enter the `tanstack/tanstack.com` directory, install the dependencies and run the app in dev mode:58+59+```sh60+cd tanstack.com61+pnpm i62+# The app will run on https://localhost:3000 by default63+pnpm dev64+```65+66+Now you can visit http://localhost:3000/form/latest/docs/overview in the browser and see the changes you make in `tanstack/form/docs`.67+68+ [!NOTE]69+ The updated pages need to be manually reloaded in the browser.70+71+ [!WARNING]72+ You will need to update the `docs/config.json` file (in the project's repo) if you add a new doc page!examples/solid/start-basic-auth/src/routes/_authed.tsx lines 17 to 24@@ -0,0 +4,21 @@4+import { Login } from '~/components/Login'5+import { useAppSession } from '~/utils/session'6+7+export const loginFn = createServerFn({ method: 'POST' })8+ .inputValidator((d: { email: string; password: string }) => d)9+ .handler(async ({ data }) => {10+ // Find the user11+ const user = await prismaClient.user.findUnique({12+ where: {13+ email: data.email,14+ },15+ })16+17+ // Check if the user exists18+ if (!user) {19+ return {20+ error: true,21+ userNotFound: true,22+ message: 'User not found',23+ }24+ }examples/solid/start-basic-auth/src/routes/_authed.tsx lines 27 to 28@@ -0,0 +8,21 @@8+ .inputValidator((d: { email: string; password: string }) => d)9+ .handler(async ({ data }) => {10+ // Find the user11+ const user = await prismaClient.user.findUnique({12+ where: {13+ email: data.email,14+ },15+ })16+17+ // Check if the user exists18+ if (!user) {19+ return {20+ error: true,21+ userNotFound: true,22+ message: 'User not found',23+ }24+ }25+26+ // Check if the password is correct27+ const hashedPassword = await hashPassword(data.password)28+examples/solid/start-basic-auth/src/routes/_authed/posts.$postId.tsx lines 21 to 28@@ -0,0 +8,21 @@8+}9+10+function PostComponent() {11+ const post = Route.useLoaderData()12+13+ return (14+ <div class="space-y-2">15+ <h4 class="text-xl font-bold underline">{post().title}</h4>16+ <div class="text-sm">{post().body}</div>17+ </div>18+ )19+}20+21+export const Route = createFileRoute('/_authed/posts/$postId')({22+ loader: ({ params: { postId } }) => fetchPost({ data: postId }),23+ errorComponent: PostErrorComponent,24+ component: PostComponent,25+ notFoundComponent: () => {26+ return <NotFound>Post not found</NotFound>27+ },28+})examples/solid/start-basic-auth/src/routes/_authed/posts.route.tsx lines 21 to 23@@ -0,0 +3,21 @@3+4+export const Route = createFileRoute('/_authed/posts')({5+ loader: () => fetchPosts(),6+ component: PostsComponent,7+})8+9+function PostsComponent() {10+ const posts = Route.useLoaderData()11+12+ return (13+ <div class="p-2 flex gap-2">14+ <ul class="list-disc pl-4">15+ {[...posts(), { id: 'i-do-not-exist', title: 'Non-existent Post' }].map(16+ (post) => {17+ return (18+ <li class="whitespace-nowrap">19+ <Link20+ to="/posts/$postId"21+ params={{22+ postId: post.id,23+ }}examples/solid/start-basic-auth/src/routes/signup.tsx lines 20 to 21@@ -0,0 +1,21 @@1+import { createFileRoute, redirect } from '@tanstack/solid-router'2+import { createServerFn, useServerFn } from '@tanstack/solid-start'3+import { hashPassword, prismaClient } from '~/utils/prisma'4+import { useMutation } from '~/hooks/useMutation'5+import { Auth } from '~/components/Auth'6+import { useAppSession } from '~/utils/session'7+8+export const signupFn = createServerFn({ method: 'POST' })9+ .inputValidator(10+ (d: { email: string; password: string; redirectUrl?: string }) => d,11+ )12+ .handler(async ({ data }) => {13+ // Check if the user already exists14+ const found = await prismaClient.user.findUnique({15+ where: {16+ email: data.email,17+ },18+ })19+20+ // Encrypt the password using Sha256 into plaintext21+ const password = await hashPassword(data.password)examples/solid/start-basic-auth/src/routes/signup.tsx lines 26 to 44@@ -0,0 +24,21 @@24+ const session = await useAppSession()25+26+ if (found) {27+ if (found.password !== password) {28+ return {29+ error: true,30+ userExists: true,31+ message: 'User already exists',32+ }33+ }34+35+ // Store the user's email in the session36+ await session.update({37+ userEmail: found.email,38+ })39+40+ // Redirect to the prev page stored in the "redirect" search param41+ throw redirect({42+ href: data.redirectUrl || '/',43+ })44+ }
birkskyum(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Adds two complete Solid Start basic authentication example projects with server-side login/signup, password hashing, session management, protected routes via Prisma SQLite database, and end-to-end tests. Projects demonstrate authentication workflows, protected route guards, and form-based UI interactions.
Changes#
e2e/solid-start/basic-auth/.env,.gitignore,.prettierignore,package.json,tsconfig.json,vite.config.ts,playwright.config.ts,postcss.config.mjs,tailwind.config.mjse2e/solid-start/basic-auth/prisma/schema.prisma,prisma/migrations/...,migration_lock.tomle2e/solid-start/basic-auth/src/components/Auth.tsx,DefaultCatchBoundary.tsx,Login.tsx,NotFound.tsxe2e/solid-start/basic-auth/src/router.tsx,routeTree.gen.ts,routes/__root.tsx,routes/_authed.tsx,routes/_authed/posts.tsx,routes/_authed/posts.$postId.tsx,routes/_authed/posts.index.tsx,routes/index.tsx,routes/login.tsx,routes/logout.tsx,routes/signup.tsxe2e/solid-start/basic-auth/src/hooks/useMutation.ts,utils/prisma.ts,utils/session.ts,utils/posts.ts,utils/seo.tse2e/solid-start/basic-auth/src/styles/app.css, public assetse2e/solid-start/basic-auth/tests/app.spec.ts,mock-db-setup.test.ts,mock-db-teardown.test.tsexamples/solid/start-basic-auth/.env,.gitignore,.prettierignore,.vscode/settings.json,package.json,tsconfig.json,vite.config.ts,postcss.config.mjs,tailwind.config.mjs,README.mdexamples/solid/start-basic-auth/prisma/schema.prisma,prisma/migrations/...,migration_lock.tomlexamples/solid/start-basic-auth/src/components/Auth.tsx,DefaultCatchBoundary.tsx,Login.tsx,NotFound.tsxexamples/solid/start-basic-auth/src/router.tsx,routeTree.gen.ts,routes/__root.tsx,routes/_authed.tsx,routes/_authed/posts.tsx,routes/_authed/posts.$postId.tsx,routes/_authed/posts.index.tsx,routes/index.tsx,routes/login.tsx,routes/logout.tsx,routes/signup.tsxexamples/solid/start-basic-auth/src/hooks/useMutation.ts,utils/prisma.ts,utils/session.ts,utils/posts.ts,utils/seo.tsexamples/solid/start-basic-auth/src/styles/app.css, public assetsSequence Diagram#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~75 minutes
The PR introduces substantial new code across two mirrored project directories with intricate authentication logic, server functions, protected route guards, session management, and database integration. While most files are duplicated between e2e and examples (reducing unique reasoning), the authentication flows are non-trivial, involving password hashing, Prisma queries, session handling, and conditional UI rendering. Route tree generation, server-side data fetching, and error boundary logic require careful review for correctness and security.
Possibly related PRs#
useSessionimport from a server-specific entry point inutils/session.ts, directly related to the session hook implementation in this PR.routeTree.gen.tsfiles introduced in this PR.Suggested labels#
package: solid-router,package: solid-start,example,e2e-testSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share