Compare commits
50 Commits
blitz@2.0.
...
@blitzjs/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17669b3af8 | ||
|
|
ec6299c36a | ||
|
|
6ac2d3412a | ||
|
|
85f9959d1f | ||
|
|
354f0440d6 | ||
|
|
ac365a0656 | ||
|
|
0729291099 | ||
|
|
9cf924ee86 | ||
|
|
b545a38b87 | ||
|
|
1463a20471 | ||
|
|
0e762fb557 | ||
|
|
6fe860512c | ||
|
|
adfe8ff919 | ||
|
|
980869fbc8 | ||
|
|
00f6d5576a | ||
|
|
1945d85db2 | ||
|
|
b0c21b0706 | ||
|
|
931156c352 | ||
|
|
1436e76180 | ||
|
|
c3bb5cd95b | ||
|
|
8b08fe4e38 | ||
|
|
604dc3b345 | ||
|
|
20fb3b9427 | ||
|
|
66ea6ec0cb | ||
|
|
8490b07246 | ||
|
|
f15a519017 | ||
|
|
cfcd3f83df | ||
|
|
adabb11a0c | ||
|
|
909dc76087 | ||
|
|
c5c727cb67 | ||
|
|
6ff9ec0d75 | ||
|
|
da17cc8a24 | ||
|
|
89bf993a1d | ||
|
|
68f129491c | ||
|
|
c096891bf0 | ||
|
|
81b4b41a99 | ||
|
|
e8271d579c | ||
|
|
9e798b152b | ||
|
|
3c6f43a11d | ||
|
|
8107138e2f | ||
|
|
8cb1134d94 | ||
|
|
2073714f8d | ||
|
|
9631c45833 | ||
|
|
2150dcc3e7 | ||
|
|
63605961b4 | ||
|
|
d711948809 | ||
|
|
1f6b0b54c2 | ||
|
|
4603a2b7bd | ||
|
|
01f3a03ea9 | ||
|
|
36e26193b7 |
6
.changeset/big-phones-bow.md
Normal file
6
.changeset/big-phones-bow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
add mounted check inside withBlitz
|
||||
@@ -7,5 +7,5 @@
|
||||
"access": "restricted",
|
||||
"baseBranch": "main",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": ["web", "test-*"]
|
||||
"ignore": ["web", "test-*", "toolkit-app"]
|
||||
}
|
||||
|
||||
5
.changeset/cool-doors-invent.md
Normal file
5
.changeset/cool-doors-invent.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/rpc": patch
|
||||
---
|
||||
|
||||
Add invokeWithCtx function
|
||||
5
.changeset/empty-berries-rule.md
Normal file
5
.changeset/empty-berries-rule.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
fix app generator for pnpm unmet dependency
|
||||
5
.changeset/fair-wombats-sneeze.md
Normal file
5
.changeset/fair-wombats-sneeze.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
added superjson
|
||||
5
.changeset/famous-kings-explain.md
Normal file
5
.changeset/famous-kings-explain.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
updated nextjs version in generator & npmrc file
|
||||
5
.changeset/fast-trainers-kneel.md
Normal file
5
.changeset/fast-trainers-kneel.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
Export Zod utils from blitz core package
|
||||
5
.changeset/four-meals-fry.md
Normal file
5
.changeset/four-meals-fry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
export BlitzPage & BlitzLayout types from @blitzjs/next
|
||||
6
.changeset/hot-drinks-approve.md
Normal file
6
.changeset/hot-drinks-approve.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
5
.changeset/modern-cameras-pull.md
Normal file
5
.changeset/modern-cameras-pull.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
Support `prefetchBlitzQuery` in gSSP and gSP
|
||||
5
.changeset/moody-squids-cheer.md
Normal file
5
.changeset/moody-squids-cheer.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
test automated publish
|
||||
5
.changeset/nice-starfishes-live.md
Normal file
5
.changeset/nice-starfishes-live.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
add mounted check to app generator template
|
||||
11
.changeset/plenty-bottles-swim.md
Normal file
11
.changeset/plenty-bottles-swim.md
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
"blitz": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
- Add mounted check to withBlitz
|
||||
- Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- Support prefetchBlitzQuery in gSP and gSSP
|
||||
- Add db seed cli command
|
||||
- Add try/catch to changePassword mutation
|
||||
5
.changeset/poor-penguins-look.md
Normal file
5
.changeset/poor-penguins-look.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
add `db seed` cli command
|
||||
5
.changeset/poor-shrimps-think.md
Normal file
5
.changeset/poor-shrimps-think.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
Setup SuperJson for GSSP and GSP
|
||||
@@ -13,22 +13,49 @@
|
||||
"@blitzjs/config": "0.0.0",
|
||||
"@blitzjs/generator": "2.0.0-alpha.0",
|
||||
"template": "0.0.0",
|
||||
"toolkit-app": "1.0.0"
|
||||
"toolkit-app": "1.0.0",
|
||||
"test-qm": "0.0.0",
|
||||
"test-no-suspense": "0.0.0",
|
||||
"test-trailing-slash": "0.0.0"
|
||||
},
|
||||
"changesets": [
|
||||
"big-phones-bow",
|
||||
"breezy-cameras-double",
|
||||
"cool-doors-invent",
|
||||
"dirty-monkeys-greet",
|
||||
"empty-berries-rule",
|
||||
"fair-wombats-sneeze",
|
||||
"famous-kings-explain",
|
||||
"fast-trainers-kneel",
|
||||
"flat-bees-approve",
|
||||
"four-meals-fry",
|
||||
"great-months-train",
|
||||
"hot-drinks-approve",
|
||||
"lovely-colts-share",
|
||||
"modern-cameras-pull",
|
||||
"moody-squids-cheer",
|
||||
"nice-starfishes-live",
|
||||
"nine-onions-admire",
|
||||
"ninety-pets-heal",
|
||||
"plenty-bottles-swim",
|
||||
"poor-peas-lick",
|
||||
"poor-penguins-look",
|
||||
"poor-shrimps-think",
|
||||
"quiet-feet-travel",
|
||||
"rich-chairs-invent",
|
||||
"sharp-falcons-begin",
|
||||
"silent-colts-reply",
|
||||
"small-socks-confess",
|
||||
"stupid-walls-sell",
|
||||
"swift-drinks-dress",
|
||||
"ten-rivers-burn",
|
||||
"tender-pianos-check",
|
||||
"thirty-countries-build",
|
||||
"twenty-beans-pump"
|
||||
"twenty-beans-pump",
|
||||
"two-kiwis-help",
|
||||
"unlucky-papayas-sleep",
|
||||
"weak-suns-shave",
|
||||
"wicked-ghosts-cough",
|
||||
"wise-frogs-give"
|
||||
]
|
||||
}
|
||||
|
||||
5
.changeset/rich-chairs-invent.md
Normal file
5
.changeset/rich-chairs-invent.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
Rename prefetchBlitzQuery to prefetchQuery, add prefetchInfiniteQuery
|
||||
5
.changeset/sharp-falcons-begin.md
Normal file
5
.changeset/sharp-falcons-begin.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
Use routes manifest in template app
|
||||
5
.changeset/small-socks-confess.md
Normal file
5
.changeset/small-socks-confess.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/auth": patch
|
||||
---
|
||||
|
||||
Add passport adapter to @blitzjs/auth
|
||||
8
.changeset/stupid-walls-sell.md
Normal file
8
.changeset/stupid-walls-sell.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"blitz": patch
|
||||
"@blitzjs/auth": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/rpc": patch
|
||||
---
|
||||
|
||||
testing set dist-tag
|
||||
7
.changeset/tender-pianos-check.md
Normal file
7
.changeset/tender-pianos-check.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"blitz": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
various improvements and fixes
|
||||
5
.changeset/two-kiwis-help.md
Normal file
5
.changeset/two-kiwis-help.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
fix generate cli command
|
||||
5
.changeset/unlucky-papayas-sleep.md
Normal file
5
.changeset/unlucky-papayas-sleep.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
remove console logs inside onPostInstall in the new cli command
|
||||
5
.changeset/weak-suns-shave.md
Normal file
5
.changeset/weak-suns-shave.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
Move blitz config to next.config.js
|
||||
5
.changeset/wicked-ghosts-cough.md
Normal file
5
.changeset/wicked-ghosts-cough.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
fix template sourcepath because of new env variable
|
||||
5
.changeset/wise-frogs-give.md
Normal file
5
.changeset/wise-frogs-give.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
use latest tag for generator template on rpc & auth packages
|
||||
44
.github/workflows/release.yml
vendored
Normal file
44
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 16.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: Creating .npmrc
|
||||
run: |
|
||||
cat << EOF > "$HOME/.npmrc"
|
||||
//registry.npmjs.org/:_authToken=$NPM_TOKEN
|
||||
EOF
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Pre-publish
|
||||
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
|
||||
with:
|
||||
version: 6.32.6
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm build
|
||||
|
||||
- name: Create Release Pull Request
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
publish: pnpm release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
1
.npmrc
1
.npmrc
@@ -1,4 +1,5 @@
|
||||
save-exact=true
|
||||
strict-peer-dependencies=false
|
||||
|
||||
public-hoist-pattern[]=secure-password
|
||||
public-hoist-pattern[]=*types*
|
||||
|
||||
@@ -1,5 +1,80 @@
|
||||
# toolkit-app
|
||||
|
||||
## 1.0.1-alpha.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.21
|
||||
- @blitzjs/auth@2.0.0-alpha.21
|
||||
- @blitzjs/next@2.0.0-alpha.21
|
||||
- @blitzjs/rpc@2.0.0-alpha.21
|
||||
- @blitzjs/config@2.0.0-alpha.21
|
||||
|
||||
## 1.0.1-alpha.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- blitz@2.0.0-alpha.20
|
||||
- @blitzjs/auth@2.0.0-alpha.20
|
||||
- @blitzjs/next@2.0.0-alpha.20
|
||||
- @blitzjs/rpc@2.0.0-alpha.20
|
||||
- @blitzjs/config@2.0.0-alpha.20
|
||||
|
||||
## 1.0.1-alpha.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- Updated dependencies [2150dcc3]
|
||||
- @blitzjs/next@2.0.0-alpha.19
|
||||
- blitz@2.0.0-alpha.19
|
||||
- @blitzjs/auth@2.0.0-alpha.19
|
||||
- @blitzjs/rpc@2.0.0-alpha.19
|
||||
- @blitzjs/config@2.0.0-alpha.19
|
||||
|
||||
## 1.0.1-alpha.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- blitz@2.0.0-alpha.18
|
||||
- @blitzjs/auth@2.0.0-alpha.18
|
||||
- @blitzjs/next@2.0.0-alpha.18
|
||||
- @blitzjs/rpc@2.0.0-alpha.18
|
||||
- @blitzjs/config@2.0.0-alpha.18
|
||||
|
||||
## 1.0.1-alpha.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.17
|
||||
- @blitzjs/auth@2.0.0-alpha.17
|
||||
- @blitzjs/next@2.0.0-alpha.17
|
||||
- @blitzjs/rpc@2.0.0-alpha.17
|
||||
- @blitzjs/config@2.0.0-alpha.17
|
||||
|
||||
## 1.0.1-alpha.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- blitz@2.0.0-alpha.16
|
||||
- @blitzjs/auth@2.0.0-alpha.16
|
||||
- @blitzjs/next@2.0.0-alpha.16
|
||||
- @blitzjs/rpc@2.0.0-alpha.16
|
||||
- @blitzjs/config@2.0.0-alpha.16
|
||||
|
||||
## 1.0.1-alpha.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.15
|
||||
- @blitzjs/auth@2.0.0-alpha.15
|
||||
- @blitzjs/next@2.0.0-alpha.15
|
||||
- @blitzjs/rpc@2.0.0-alpha.15
|
||||
- @blitzjs/config@2.0.0-alpha.15
|
||||
|
||||
## 1.0.1-alpha.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Form, FORM_ERROR } from "app/core/components/Form"
|
||||
import login from "app/auth/mutations/login"
|
||||
import { Login } from "app/auth/validations"
|
||||
import { useMutation } from "@blitzjs/rpc"
|
||||
import { Routes } from "@blitzjs/next"
|
||||
|
||||
type LoginFormProps = {
|
||||
onSuccess?: (user: PromiseReturnType<typeof login>) => void
|
||||
@@ -39,7 +40,7 @@ export const LoginForm = (props: LoginFormProps) => {
|
||||
<LabeledTextField name="email" label="Email" placeholder="Email" />
|
||||
<LabeledTextField name="password" label="Password" placeholder="Password" type="password" />
|
||||
<div>
|
||||
<Link href="/auth/forgot-password" passHref>
|
||||
<Link href={Routes.ForgotPasswordPage()} passHref>
|
||||
<a>Forgot your password?</a>
|
||||
</Link>
|
||||
</div>
|
||||
@@ -47,7 +48,7 @@ export const LoginForm = (props: LoginFormProps) => {
|
||||
|
||||
<div style={{ marginTop: "1rem" }}>
|
||||
Or{" "}
|
||||
<Link href="/auth/signup" passHref>
|
||||
<Link href={Routes.SignupPage()} passHref>
|
||||
<a>Sign Up</a>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
47
apps/toolkit-app/db/migrations/20220427214932_/migration.sql
Normal file
47
apps/toolkit-app/db/migrations/20220427214932_/migration.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"name" TEXT,
|
||||
"email" TEXT NOT NULL,
|
||||
"hashedPassword" TEXT,
|
||||
"role" TEXT NOT NULL DEFAULT 'USER'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Session" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"expiresAt" DATETIME,
|
||||
"handle" TEXT NOT NULL,
|
||||
"hashedSessionToken" TEXT,
|
||||
"antiCSRFToken" TEXT,
|
||||
"publicData" TEXT,
|
||||
"privateData" TEXT,
|
||||
"userId" INTEGER,
|
||||
CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Token" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"hashedToken" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"expiresAt" DATETIME NOT NULL,
|
||||
"sentTo" TEXT NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Token_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Session_handle_key" ON "Session"("handle");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Token_hashedToken_type_key" ON "Token"("hashedToken", "type");
|
||||
@@ -1,4 +1,4 @@
|
||||
// import db from "./index"
|
||||
import { db } from "./index"
|
||||
|
||||
/*
|
||||
* This seed function is executed when you run `blitz db seed`.
|
||||
@@ -7,9 +7,15 @@
|
||||
* to easily generate realistic data.
|
||||
*/
|
||||
const seed = async () => {
|
||||
// for (let i = 0; i < 5; i++) {
|
||||
// await db.project.create({ data: { name: "Project " + i } })
|
||||
// }
|
||||
await db.$reset()
|
||||
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await db.user.create({
|
||||
data: {
|
||||
email: "test@test.com",
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default seed
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "toolkit-app",
|
||||
"version": "1.0.1-alpha.9",
|
||||
"version": "1.0.1-alpha.16",
|
||||
"scripts": {
|
||||
"start:dev": "pnpm run prisma:start && next dev",
|
||||
"buildapp": "prisma generate && next build",
|
||||
"buildapp": "NODE_ENV=production pnpm blitz codegen && pnpm prisma generate && next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"prisma:start": "prisma generate && prisma migrate deploy",
|
||||
@@ -29,8 +29,8 @@
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@hookform/resolvers": "2.8.8",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:2.0.0-alpha.14",
|
||||
"next": "12.1.1",
|
||||
"blitz": "workspace:2.0.0-alpha.28",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
@@ -45,7 +45,7 @@
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/preview-email": "2.0.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ErrorFallbackProps, ErrorComponent, ErrorBoundary } from "@blitzjs/next"
|
||||
import { ErrorFallbackProps, ErrorComponent, ErrorBoundary, AppProps } from "@blitzjs/next"
|
||||
import { AuthenticationError, AuthorizationError } from "blitz"
|
||||
import type { AppProps } from "next/app"
|
||||
import React, { Suspense } from "react"
|
||||
import React from "react"
|
||||
import { withBlitz } from "app/blitz-client"
|
||||
|
||||
function RootErrorFallback({ error }: ErrorFallbackProps) {
|
||||
@@ -27,9 +26,7 @@ function RootErrorFallback({ error }: ErrorFallbackProps) {
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense>
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { useRouter } from "next/router"
|
||||
import Layout from "app/core/layouts/Layout"
|
||||
import { SignupForm } from "app/auth/components/SignupForm"
|
||||
import { Routes } from "@blitzjs/next"
|
||||
|
||||
const SignupPage = () => {
|
||||
const router = useRouter()
|
||||
|
||||
return (
|
||||
<Layout title="Sign Up">
|
||||
<SignupForm onSuccess={() => router.push("/")} />
|
||||
<SignupForm onSuccess={() => router.push(Routes.Home())} />
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useCurrentUser } from "app/core/hooks/useCurrentUser"
|
||||
import logout from "app/auth/mutations/logout"
|
||||
import logo from "public/logo.png"
|
||||
import { useMutation } from "@blitzjs/rpc"
|
||||
import { Routes } from "@blitzjs/next"
|
||||
|
||||
/*
|
||||
* This file is just for a pleasant getting started page for your new app.
|
||||
@@ -37,12 +38,12 @@ const UserInfo = () => {
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
<Link href="/auth/signup" passHref>
|
||||
<Link href={Routes.SignupPage()} passHref>
|
||||
<a className="button small">
|
||||
<strong>Sign Up</strong>
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/auth/login" passHref>
|
||||
<Link href={Routes.LoginPage()} passHref>
|
||||
<a className="button small">
|
||||
<strong>Login</strong>
|
||||
</a>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"baseUrl": "./",
|
||||
"baseUrl": ".",
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": false,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {setupBlitzServer} from "@blitzjs/next"
|
||||
import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth"
|
||||
import {prisma as db} from "../prisma/index"
|
||||
import db from "db"
|
||||
import {simpleRolesIsAuthorized} from "@blitzjs/auth"
|
||||
|
||||
const {gSSP, gSP, api} = setupBlitzServer({
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {Ctx} from "blitz"
|
||||
import {prisma} from "../../prisma"
|
||||
import {User} from "prisma"
|
||||
import db, {User} from "db"
|
||||
|
||||
export default async function createUser(
|
||||
input: {name: string; email: string},
|
||||
@@ -8,7 +7,7 @@ export default async function createUser(
|
||||
): Promise<User> {
|
||||
ctx.session.$authorize()
|
||||
|
||||
const user = await prisma.user.create({data: {name: input.name, email: input.email}})
|
||||
const user = await db.user.create({data: {name: input.name, email: input.email}})
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
27
apps/web/app/queries/getInfiniteUsers.ts
Normal file
27
apps/web/app/queries/getInfiniteUsers.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {resolver} from "@blitzjs/rpc"
|
||||
import {paginate} from "blitz"
|
||||
import db, {Prisma} from "db"
|
||||
|
||||
interface GetUsersInput
|
||||
extends Pick<Prisma.UserFindManyArgs, "where" | "orderBy" | "skip" | "take"> {}
|
||||
|
||||
export default resolver.pipe(async ({where, orderBy, skip = 0, take = 100}: GetUsersInput) => {
|
||||
const {
|
||||
items: users,
|
||||
hasMore,
|
||||
nextPage,
|
||||
count,
|
||||
} = await paginate({
|
||||
skip,
|
||||
take,
|
||||
count: () => db.user.count({where}),
|
||||
query: (paginateArgs) => db.user.findMany({...paginateArgs, where, orderBy}),
|
||||
})
|
||||
|
||||
return {
|
||||
users,
|
||||
nextPage,
|
||||
hasMore,
|
||||
count,
|
||||
}
|
||||
})
|
||||
@@ -1,11 +1,10 @@
|
||||
import {Ctx} from "blitz"
|
||||
import {prisma} from "../../prisma"
|
||||
import {User} from "prisma"
|
||||
import db, {User} from "db"
|
||||
|
||||
export default async function getUsers(_input: {}, ctx: Ctx): Promise<User[]> {
|
||||
ctx.session.$authorize()
|
||||
|
||||
const users = await prisma.user.findMany()
|
||||
const users = await db.user.findMany()
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
8
apps/web/app/queries/getUsersAuth.ts
Normal file
8
apps/web/app/queries/getUsersAuth.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import {resolver} from "@blitzjs/rpc"
|
||||
import db from "db"
|
||||
|
||||
export default resolver.pipe(resolver.authorize(), async () => {
|
||||
const users = await db.user.findMany()
|
||||
|
||||
return users
|
||||
})
|
||||
8
apps/web/db/index.ts
Normal file
8
apps/web/db/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import {enhancePrisma} from "blitz"
|
||||
import {PrismaClient} from "@prisma/client"
|
||||
|
||||
const EnhancedPrisma = enhancePrisma(PrismaClient)
|
||||
|
||||
export * from "@prisma/client"
|
||||
const prisma = new EnhancedPrisma()
|
||||
export default prisma
|
||||
@@ -6,5 +6,10 @@ const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz(
|
||||
withBundleAnalyzer({
|
||||
reactStrictMode: true,
|
||||
blitz: {
|
||||
customServer: {
|
||||
hotReload: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
"prisma:studio": "prisma studio",
|
||||
"test": "jest"
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "./db/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "workspace:*",
|
||||
"@blitzjs/config": "workspace:*",
|
||||
@@ -19,9 +22,12 @@
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@prisma/client": "3.9.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/passport-twitter": "1.0.37",
|
||||
"blitz": "workspace:*",
|
||||
"jest": "27.5.1",
|
||||
"next": "12.1.1",
|
||||
"next": "12.1.6-canary.17",
|
||||
"passport-mock-strategy": "2.0.0",
|
||||
"passport-twitter": "1.0.4",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
@@ -29,7 +35,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary} from "@blitzjs/next"
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary, AppProps} from "@blitzjs/next"
|
||||
import {AuthenticationError, AuthorizationError} from "blitz"
|
||||
import type {AppProps} from "next/app"
|
||||
import React, {Suspense} from "react"
|
||||
import React from "react"
|
||||
import {withBlitz} from "app/blitz-client"
|
||||
|
||||
function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
@@ -27,9 +26,7 @@ function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
function MyApp({Component, pageProps}: AppProps) {
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense>
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
44
apps/web/pages/api/auth/[...auth].ts
Normal file
44
apps/web/pages/api/auth/[...auth].ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {passportAuth} from "@blitzjs/auth"
|
||||
import {api} from "app/blitz-server"
|
||||
import db from "db"
|
||||
import {Strategy as TwitterStrategy} from "passport-twitter"
|
||||
|
||||
export default api(
|
||||
passportAuth({
|
||||
successRedirectUrl: "/",
|
||||
errorRedirectUrl: "/",
|
||||
strategies: [
|
||||
{
|
||||
strategy: new TwitterStrategy(
|
||||
{
|
||||
consumerKey: process.env.TWITTER_CONSUMER_KEY as string,
|
||||
consumerSecret: process.env.TWITTER_CONSUMER_SECRET as string,
|
||||
accessTokenURL: "https://api.twitter.com/oauth/access_token",
|
||||
callbackURL: "http://127.0.0.1:3000/api/auth/twitter/callback",
|
||||
includeEmail: true,
|
||||
},
|
||||
async function (_token, _tokenSecret, profile, done) {
|
||||
const email = profile.emails?.[0]?.value ?? "blitz@test.com"
|
||||
|
||||
const user = await db.user.upsert({
|
||||
where: {email},
|
||||
create: {
|
||||
email,
|
||||
name: profile.displayName,
|
||||
},
|
||||
update: {email},
|
||||
})
|
||||
|
||||
const publicData = {
|
||||
userId: user.id,
|
||||
roles: [user.role],
|
||||
source: "twitter",
|
||||
}
|
||||
|
||||
done(undefined, {publicData})
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
@@ -1,14 +1,13 @@
|
||||
import {api} from "app/blitz-server"
|
||||
import {SessionContext} from "@blitzjs/auth"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
|
||||
export default api(async (_req, res, ctx) => {
|
||||
const blitzContext = ctx
|
||||
|
||||
const publicData = blitzContext.session.$publicData
|
||||
|
||||
const sessions = await prisma.session.findMany({})
|
||||
const sessionsCount = await prisma.session.count({})
|
||||
const sessions = await db.session.findMany({})
|
||||
const sessionsCount = await db.session.count({})
|
||||
|
||||
res.status(200).json({
|
||||
userId: blitzContext.session.userId,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {NextApiRequest, NextApiResponse} from "next"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await prisma.session.findFirst({
|
||||
const session = await db.session.findFirst({
|
||||
where: {
|
||||
handle: "test",
|
||||
},
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {api} from "app/blitz-server"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
|
||||
export default api(async (_req, res) => {
|
||||
const sessions = await prisma.session.deleteMany()
|
||||
const sessionsCount = await prisma.session.count()
|
||||
const sessions = await db.session.deleteMany()
|
||||
const sessionsCount = await db.session.count()
|
||||
|
||||
res.status(200).json({
|
||||
activeSessions: sessions,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {setPublicDataForUser} from "@blitzjs/auth"
|
||||
import {api} from "app/blitz-server"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
|
||||
export default api(async (req, res, ctx) => {
|
||||
if (ctx.session.$thisIsAuthorized()) {
|
||||
ctx.session.$publicData
|
||||
|
||||
await prisma.user.update({
|
||||
await db.user.update({
|
||||
where: {id: ctx.session.userId as number},
|
||||
data: {role: req.query.role as string},
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {api} from "app/blitz-server"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
import {SecurePassword} from "@blitzjs/auth"
|
||||
|
||||
export const authenticateUser = async (email: string, password: string) => {
|
||||
const user = await prisma.user.findFirst({where: {email}})
|
||||
const user = await db.user.findFirst({where: {email}})
|
||||
if (!user) throw new Error("Authentication Error")
|
||||
|
||||
const result = await SecurePassword.verify(user.hashedPassword, password)
|
||||
@@ -11,7 +11,7 @@ export const authenticateUser = async (email: string, password: string) => {
|
||||
if (result === SecurePassword.VALID_NEEDS_REHASH) {
|
||||
// Upgrade hashed password with a more secure hash
|
||||
const improvedHash = await SecurePassword.hash(password)
|
||||
await prisma.user.update({where: {id: user.id}, data: {hashedPassword: improvedHash}})
|
||||
await db.user.update({where: {id: user.id}, data: {hashedPassword: improvedHash}})
|
||||
}
|
||||
|
||||
const {hashedPassword, ...rest} = user
|
||||
@@ -25,6 +25,7 @@ export default api(async (req, res, ctx) => {
|
||||
|
||||
await blitzContext.session.$create({
|
||||
userId: user.id,
|
||||
role: "USER",
|
||||
})
|
||||
|
||||
res.status(200).json({email: req.query.email, userId: blitzContext.session.userId})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {api} from "app/blitz-server"
|
||||
import {prisma} from "../../prisma/index"
|
||||
import db from "db"
|
||||
import {SecurePassword} from "@blitzjs/auth"
|
||||
|
||||
export default api(async (req, res, ctx) => {
|
||||
@@ -9,13 +9,14 @@ export default api(async (req, res, ctx) => {
|
||||
(req.query.password as string) || "test-password",
|
||||
)
|
||||
const email = (req.query.email as string) || "test" + Math.random() + "@test.com"
|
||||
const user = await prisma.user.create({
|
||||
const user = await db.user.create({
|
||||
data: {email, hashedPassword, role: "user"},
|
||||
select: {id: true, name: true, email: true, role: true},
|
||||
})
|
||||
|
||||
await blitzContext.session.$create({
|
||||
userId: user.id,
|
||||
role: "USER",
|
||||
})
|
||||
|
||||
res.status(200).json({userId: blitzContext.session.userId, ...user, email: req.query.email})
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import {useState} from "react"
|
||||
import {SessionContext} from "@blitzjs/auth"
|
||||
import {useMutation} from "@blitzjs/rpc"
|
||||
import createUser from "app/mutations/createUser"
|
||||
import {User} from "prisma"
|
||||
import {User} from "db"
|
||||
|
||||
function Page() {
|
||||
const [name, setName] = useState("")
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import {gSP} from "app/blitz-server"
|
||||
|
||||
export const getStaticProps = gSP(async ({ctx}) => {
|
||||
export const getStaticProps = gSP<{data: {test: string}}>(async ({ctx}) => {
|
||||
return {
|
||||
props: {
|
||||
data: {
|
||||
// userId: ctx?.session.userId,
|
||||
// session: {
|
||||
// id: session.userId,
|
||||
// publicData: session.$publicData,
|
||||
// },
|
||||
test: "hello",
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export const getServerSideProps = gSSP<Props>(async ({ctx}) => {
|
||||
props: {
|
||||
userId: session.userId,
|
||||
publicData: session.$publicData,
|
||||
publishedAt: new Date(0),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
32
apps/web/pages/page-with-inf-prefetch.tsx
Normal file
32
apps/web/pages/page-with-inf-prefetch.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import {useInfiniteQuery} from "@blitzjs/rpc"
|
||||
import {gSSP} from "app/blitz-server"
|
||||
import getInfiniteUsers from "app/queries/getInfiniteUsers"
|
||||
|
||||
export const getServerSideProps = gSSP(async ({ctx}) => {
|
||||
const {prefetchInfiniteQuery} = ctx
|
||||
|
||||
await prefetchInfiniteQuery(getInfiniteUsers, {}, {})
|
||||
return {props: {}}
|
||||
})
|
||||
|
||||
function PageWithPrefetchInfiniteQuery(props) {
|
||||
const [usersPages] = useInfiniteQuery(getInfiniteUsers, (page = {take: 3, skip: 0}) => page, {
|
||||
getNextPageParam: (lastPage) => lastPage.nextPage,
|
||||
})
|
||||
return (
|
||||
<div>
|
||||
{usersPages.map((usersPage) =>
|
||||
usersPage?.users.map((u) => (
|
||||
<div key={u.createdAt.toDateString()}>
|
||||
<p>name: {u.name}</p>
|
||||
<p>role: {u.role}</p>
|
||||
<p>email: {u.email}</p>
|
||||
<hr />
|
||||
</div>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PageWithPrefetchInfiniteQuery
|
||||
31
apps/web/pages/page-with-invoke-ctx.tsx
Normal file
31
apps/web/pages/page-with-invoke-ctx.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import {SessionContext} from "@blitzjs/auth"
|
||||
import {invokeWithCtx} from "@blitzjs/rpc"
|
||||
import {gSSP} from "app/blitz-server"
|
||||
import getUsersAuth from "app/queries/getUsersAuth"
|
||||
|
||||
type Props = {
|
||||
userId: unknown
|
||||
publicData: SessionContext["$publicData"]
|
||||
}
|
||||
|
||||
export const getServerSideProps = gSSP<Props>(async ({ctx}) => {
|
||||
const {session} = ctx
|
||||
|
||||
const users = await invokeWithCtx(getUsersAuth, {}, ctx)
|
||||
|
||||
console.log({users})
|
||||
|
||||
return {
|
||||
props: {
|
||||
userId: session.userId,
|
||||
publicData: session.$publicData,
|
||||
publishedAt: new Date(0),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
function PageWithInvokeCtx(props: Props) {
|
||||
return <div>{JSON.stringify(props, null, 2)}</div>
|
||||
}
|
||||
|
||||
export default PageWithInvokeCtx
|
||||
28
apps/web/pages/page-with-prefetch.tsx
Normal file
28
apps/web/pages/page-with-prefetch.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import {useQuery} from "@blitzjs/rpc"
|
||||
import {gSSP} from "app/blitz-server"
|
||||
import getUsers from "app/queries/getUsers"
|
||||
|
||||
export const getServerSideProps = gSSP(async ({ctx}) => {
|
||||
const {prefetchQuery} = ctx
|
||||
|
||||
await prefetchQuery(getUsers, {}, {})
|
||||
return {props: {}}
|
||||
})
|
||||
|
||||
function PageWithPrefetch(props) {
|
||||
const [users] = useQuery(getUsers, {})
|
||||
return (
|
||||
<div>
|
||||
{users.map((u) => (
|
||||
<div key={u.createdAt.toDateString()}>
|
||||
<p>name: {u.name}</p>
|
||||
<p>role: {u.role}</p>
|
||||
<p>email: {u.email}</p>
|
||||
<hr />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PageWithPrefetch
|
||||
15
apps/web/types.ts
Normal file
15
apps/web/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {SimpleRolesIsAuthorized} from "@blitzjs/auth"
|
||||
import {User} from "db"
|
||||
|
||||
export type Role = "ADMIN" | "USER"
|
||||
|
||||
declare module "@blitzjs/auth" {
|
||||
export interface Session {
|
||||
isAuthorized: SimpleRolesIsAuthorized<Role>
|
||||
PublicData: {
|
||||
userId: User["id"]
|
||||
role: Role
|
||||
views?: number
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:*",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "12.1.1",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0"
|
||||
@@ -29,7 +29,7 @@
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"eslint": "7.32.0",
|
||||
"fs-extra": "10.0.1",
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary} from "@blitzjs/next"
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary, AppProps} from "@blitzjs/next"
|
||||
import {AuthenticationError, AuthorizationError} from "blitz"
|
||||
import type {AppProps} from "next/app"
|
||||
import React from "react"
|
||||
import {withBlitz} from "../app/blitz-client"
|
||||
|
||||
function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
if (error instanceof AuthenticationError) {
|
||||
return <div>Error: You are not authenticated</div>
|
||||
return <div id="error">Error: You are not authenticated</div>
|
||||
} else if (error instanceof AuthorizationError) {
|
||||
return (
|
||||
<ErrorComponent
|
||||
|
||||
@@ -35,20 +35,24 @@ const runTests = (mode?: string) => {
|
||||
"should render error for protected query",
|
||||
async () => {
|
||||
const browser = await webdriver(appPort, "/authenticated-page")
|
||||
let errorMsg = await browser.elementByXpath(`//*[@id="__next"]/div`)
|
||||
let errorMsg = await browser.elementById(`error`).text()
|
||||
expect(errorMsg).toMatch(/Error: You are not authenticated/)
|
||||
if (browser) browser.close()
|
||||
},
|
||||
5000 * 60 * 2,
|
||||
)
|
||||
|
||||
it("should render result for open query", async () => {
|
||||
const res = await fetch(`http://localhost:${appPort}/api/noauth`, {
|
||||
method: "GET",
|
||||
headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
it(
|
||||
"should render result for open query",
|
||||
async () => {
|
||||
const res = await fetch(`http://localhost:${appPort}/api/noauth`, {
|
||||
method: "GET",
|
||||
headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
},
|
||||
5000 * 60 * 2,
|
||||
)
|
||||
|
||||
it("sets correct cookie", async () => {
|
||||
const res = await fetch(`http://localhost:${appPort}/api/noauth`, {
|
||||
@@ -118,31 +122,33 @@ const runTests = (mode?: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
describe("dev mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
appPort = await findPort()
|
||||
app = await launchApp(appDir, appPort, {})
|
||||
await seed()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
runTests()
|
||||
})
|
||||
describe("Auth Tests", () => {
|
||||
describe("dev mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
appPort = await findPort()
|
||||
app = await launchApp(appDir, appPort, {cwd: process.cwd()})
|
||||
await seed()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
runTests()
|
||||
})
|
||||
|
||||
describe("server mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
appPort = await findPort()
|
||||
await nextBuild(appDir)
|
||||
app = await nextStart(appDir, appPort)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
describe("server mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
await nextBuild(appDir)
|
||||
appPort = await findPort()
|
||||
app = await nextStart(appDir, appPort, {cwd: process.cwd()})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
|
||||
runTests()
|
||||
runTests()
|
||||
})
|
||||
})
|
||||
|
||||
2
integration-tests/no-suspense/.env
Normal file
2
integration-tests/no-suspense/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ
|
||||
HEADLESS=true
|
||||
1
integration-tests/no-suspense/.eslintrc.js
Normal file
1
integration-tests/no-suspense/.eslintrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("@blitzjs/config/eslint")
|
||||
3
integration-tests/no-suspense/.gitignore
vendored
Normal file
3
integration-tests/no-suspense/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
*.sqlite
|
||||
20
integration-tests/no-suspense/app/blitz-client.ts
Normal file
20
integration-tests/no-suspense/app/blitz-client.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {BlitzRpcPlugin} from "@blitzjs/rpc"
|
||||
import {setupBlitzClient} from "@blitzjs/next"
|
||||
import {AuthClientPlugin} from "@blitzjs/auth"
|
||||
|
||||
const {withBlitz} = setupBlitzClient({
|
||||
plugins: [
|
||||
AuthClientPlugin({
|
||||
cookiePrefix: "no-suspense-tests-cookie-prefix",
|
||||
}),
|
||||
BlitzRpcPlugin({
|
||||
reactQueryOptions: {
|
||||
queries: {
|
||||
staleTime: 7000,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
export {withBlitz}
|
||||
16
integration-tests/no-suspense/app/blitz-server.ts
Normal file
16
integration-tests/no-suspense/app/blitz-server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import {setupBlitzServer} from "@blitzjs/next"
|
||||
import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth"
|
||||
import {simpleRolesIsAuthorized} from "@blitzjs/auth"
|
||||
import {prisma as db} from "../prisma/index"
|
||||
|
||||
const {gSSP, gSP, api} = setupBlitzServer({
|
||||
plugins: [
|
||||
AuthServerPlugin({
|
||||
cookiePrefix: "no-suspense-tests-cookie-prefix",
|
||||
storage: PrismaStorage(db as any),
|
||||
isAuthorized: simpleRolesIsAuthorized,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
export {gSSP, gSP, api}
|
||||
3
integration-tests/no-suspense/app/queries/getBasic.ts
Normal file
3
integration-tests/no-suspense/app/queries/getBasic.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default async function getBasic() {
|
||||
return "basic-result"
|
||||
}
|
||||
5
integration-tests/no-suspense/next-env.d.ts
vendored
Normal file
5
integration-tests/no-suspense/next-env.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
2
integration-tests/no-suspense/next.config.js
Normal file
2
integration-tests/no-suspense/next.config.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({})
|
||||
41
integration-tests/no-suspense/package.json
Normal file
41
integration-tests/no-suspense/package.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "test-no-suspense",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start:dev": "pnpm run prisma:start && next dev",
|
||||
"test": "pnpm run prisma:start && vitest run",
|
||||
"test-watch": "vitest",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next",
|
||||
"prisma:start": "prisma generate && prisma migrate deploy",
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "workspace:*",
|
||||
"@blitzjs/next": "workspace:*",
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:*",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:*",
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "18.0.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"eslint": "7.32.0",
|
||||
"fs-extra": "10.0.1",
|
||||
"get-port": "6.1.2",
|
||||
"node-fetch": "3.2.3",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
34
integration-tests/no-suspense/pages/_app.tsx
Normal file
34
integration-tests/no-suspense/pages/_app.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary, AppProps} from "@blitzjs/next"
|
||||
import {AuthenticationError, AuthorizationError} from "blitz"
|
||||
import React from "react"
|
||||
import {withBlitz} from "../app/blitz-client"
|
||||
|
||||
function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
if (error instanceof AuthenticationError) {
|
||||
return <div>Error: You are not authenticated</div>
|
||||
} else if (error instanceof AuthorizationError) {
|
||||
return (
|
||||
<ErrorComponent
|
||||
statusCode={error.statusCode}
|
||||
title="Sorry, you are not authorized to access this"
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<ErrorComponent
|
||||
statusCode={(error as any)?.statusCode || 400}
|
||||
title={error.message || error.name}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function MyApp({Component, pageProps}: AppProps) {
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
export default withBlitz(MyApp)
|
||||
@@ -0,0 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../app/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
23
integration-tests/no-suspense/pages/use-query.tsx
Normal file
23
integration-tests/no-suspense/pages/use-query.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import getBasic from "../app/queries/getBasic"
|
||||
import {useQuery} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
|
||||
function Content() {
|
||||
const [result, {isFetching}] = useQuery(getBasic, undefined)
|
||||
|
||||
if (isFetching) {
|
||||
return <>Loading...</>
|
||||
} else {
|
||||
return <div id="content">{result}</div>
|
||||
}
|
||||
}
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Content />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Page
|
||||
@@ -0,0 +1,47 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"name" TEXT,
|
||||
"email" TEXT NOT NULL,
|
||||
"hashedPassword" TEXT,
|
||||
"role" TEXT NOT NULL DEFAULT 'user'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Session" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"expiresAt" DATETIME,
|
||||
"handle" TEXT NOT NULL,
|
||||
"userId" INTEGER,
|
||||
"hashedSessionToken" TEXT,
|
||||
"antiCSRFToken" TEXT,
|
||||
"publicData" TEXT,
|
||||
"privateData" TEXT,
|
||||
CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Token" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"hashedToken" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"expiresAt" DATETIME NOT NULL,
|
||||
"sentTo" TEXT NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Token_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Session_handle_key" ON "Session"("handle");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Token_hashedToken_type_key" ON "Token"("hashedToken", "type");
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
||||
50
integration-tests/no-suspense/prisma/schema.prisma
Normal file
50
integration-tests/no-suspense/prisma/schema.prisma
Normal file
@@ -0,0 +1,50 @@
|
||||
datasource sqlite {
|
||||
provider = "sqlite"
|
||||
url = "file:./db.sqlite"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
name String?
|
||||
email String @unique
|
||||
hashedPassword String?
|
||||
role String @default("user")
|
||||
|
||||
sessions Session[]
|
||||
tokens Token[]
|
||||
}
|
||||
|
||||
model Session {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
expiresAt DateTime?
|
||||
handle String @unique
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId Int?
|
||||
hashedSessionToken String?
|
||||
antiCSRFToken String?
|
||||
publicData String?
|
||||
privateData String?
|
||||
}
|
||||
|
||||
model Token {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
hashedToken String
|
||||
type String
|
||||
expiresAt DateTime
|
||||
sentTo String
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int
|
||||
|
||||
@@unique([hashedToken, type])
|
||||
}
|
||||
7
integration-tests/no-suspense/prisma/seed.ts
Normal file
7
integration-tests/no-suspense/prisma/seed.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import {prisma} from "./index"
|
||||
|
||||
const seed = async () => {
|
||||
await prisma.$reset()
|
||||
}
|
||||
|
||||
export default seed
|
||||
57
integration-tests/no-suspense/test/index.test.ts
Normal file
57
integration-tests/no-suspense/test/index.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import {describe, it, expect, beforeAll, afterAll} from "vitest"
|
||||
import {killApp, findPort, launchApp, nextBuild, nextStart} from "../../utils/next-test-utils"
|
||||
import webdriver from "../../utils/next-webdriver"
|
||||
|
||||
import {join} from "path"
|
||||
|
||||
let app: any
|
||||
let appPort: number
|
||||
const appDir = join(__dirname, "../")
|
||||
|
||||
const runTests = (mode?: string) => {
|
||||
describe("useQuery without suspense", () => {
|
||||
it(
|
||||
"should render query result",
|
||||
async () => {
|
||||
const browser = await webdriver(appPort, "/use-query")
|
||||
|
||||
let text
|
||||
browser.waitForElementByCss("#content", 0)
|
||||
text = await browser.elementByCss("#content").text()
|
||||
expect(text).toMatch(/basic-result/)
|
||||
if (browser) await browser.close()
|
||||
},
|
||||
5000 * 60 * 2,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
describe("No Suspense Tests", () => {
|
||||
describe("dev mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
appPort = await findPort()
|
||||
app = await launchApp(appDir, appPort, {cwd: process.cwd()})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
runTests()
|
||||
})
|
||||
|
||||
describe("server mode", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
await nextBuild(appDir)
|
||||
appPort = await findPort()
|
||||
app = await nextStart(appDir, appPort, {cwd: process.cwd()})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}, 5000 * 60 * 2)
|
||||
afterAll(async () => await killApp(app))
|
||||
|
||||
runTests()
|
||||
})
|
||||
})
|
||||
11
integration-tests/no-suspense/tsconfig.json
Normal file
11
integration-tests/no-suspense/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "@blitzjs/config/tsconfig.nextjs.json",
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"react": ["./node_modules/@types/react"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"baseUrl": "."
|
||||
}
|
||||
1
integration-tests/qm/.eslintrc.js
Normal file
1
integration-tests/qm/.eslintrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("@blitzjs/config/eslint")
|
||||
3
integration-tests/qm/.gitignore
vendored
Normal file
3
integration-tests/qm/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
*.sqlite
|
||||
5
integration-tests/qm/next-env.d.ts
vendored
Normal file
5
integration-tests/qm/next-env.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
4
integration-tests/qm/next.config.js
Normal file
4
integration-tests/qm/next.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({
|
||||
// update me
|
||||
})
|
||||
34
integration-tests/qm/package.json
Normal file
34
integration-tests/qm/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "test-qm",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"test-watch": "vitest",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "workspace:*",
|
||||
"@blitzjs/config": "workspace:*",
|
||||
"@blitzjs/next": "workspace:*",
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:*",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-query": "3.39.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@types/react": "18.0.1",
|
||||
"@vitejs/plugin-react": "1.3.0",
|
||||
"delay": "5.0.0",
|
||||
"eslint": "7.32.0",
|
||||
"eslint-config-next": "latest",
|
||||
"eslint-plugin-testing-library": "5.0.1",
|
||||
"jsdom": "^19.0.0",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with query function 1`] = `"\\"useMutation\\" was expected to be called with a mutation but was called with a \\"query\\""`;
|
||||
|
||||
exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with regular functions 1`] = `"Either the file path to your resolver is incorrect (must be in a \\"queries\\" or \\"mutations\\" folder that isn't nested inside \\"pages\\" or \\"api\\") or you are trying to use Blitz's useQuery to fetch from third-party APIs (to do that, import useQuery directly from \\"react-query\\")"`;
|
||||
@@ -0,0 +1,5 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with mutation function 1`] = `"Cannot read properties of null (reading 'isReady')"`;
|
||||
|
||||
exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with regular functions 1`] = `"Cannot read properties of null (reading 'isReady')"`;
|
||||
55
integration-tests/qm/test/use-mutation.test.tsx
Normal file
55
integration-tests/qm/test/use-mutation.test.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import {describe, it, expect, beforeAll, vi} from "vitest"
|
||||
import {act, screen} from "@testing-library/react"
|
||||
import {useMutation} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
import {buildMutationRpc, buildQueryRpc, render} from "../../utils/blitz-test-utils"
|
||||
|
||||
beforeAll(() => {
|
||||
globalThis.__BLITZ_SESSION_COOKIE_PREFIX = "qm-test-cookie-prefix"
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
})
|
||||
|
||||
describe("useMutation", () => {
|
||||
const setupHook = (resolver: (...args: any) => Promise<any>): [{mutate?: Function}, Function] => {
|
||||
let res = {}
|
||||
|
||||
function TestHarness() {
|
||||
const [mutate, {isSuccess}] = useMutation(resolver)
|
||||
|
||||
Object.assign(res, {mutate})
|
||||
return <div id="harness">{isSuccess ? "Sent" : "Waiting"}</div>
|
||||
}
|
||||
|
||||
const ui = () => <TestHarness />
|
||||
|
||||
const {rerender} = render(ui())
|
||||
return [res, () => rerender(ui())]
|
||||
}
|
||||
|
||||
describe("useMutation calls the resolver with the argument", () => {
|
||||
// eslint-disable-next-line require-await
|
||||
const mutateFn = vi.fn()
|
||||
it("should work with Blitz mutations", async () => {
|
||||
const [res] = setupHook(buildMutationRpc(mutateFn))
|
||||
await act(async () => {
|
||||
await res.mutate!("data")
|
||||
})
|
||||
|
||||
await screen.findByText("Sent")
|
||||
expect(mutateFn).toHaveBeenCalledTimes(1)
|
||||
expect(mutateFn).toHaveBeenCalledWith("data", {fromQueryHook: true})
|
||||
})
|
||||
|
||||
it("shouldn't work with regular functions", () => {
|
||||
console.error = vi.fn()
|
||||
expect(() => setupHook(mutateFn)).toThrowErrorMatchingSnapshot()
|
||||
})
|
||||
|
||||
it("shouldn't work with query function", () => {
|
||||
console.error = vi.fn()
|
||||
const mutationFn = vi.fn()
|
||||
|
||||
expect(() => setupHook(buildQueryRpc(mutationFn))).toThrowErrorMatchingSnapshot()
|
||||
})
|
||||
})
|
||||
})
|
||||
166
integration-tests/qm/test/use-query.test.tsx
Normal file
166
integration-tests/qm/test/use-query.test.tsx
Normal file
@@ -0,0 +1,166 @@
|
||||
import {describe, it, expect, beforeAll, vi} from "vitest"
|
||||
import {act, screen, waitForElementToBeRemoved, waitFor} from "@testing-library/react"
|
||||
import {useQuery, useInfiniteQuery} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
import delay from "delay"
|
||||
import {buildMutationRpc, buildQueryRpc, render} from "../../utils/blitz-test-utils"
|
||||
|
||||
describe("useQuery", () => {
|
||||
it("Placeholder", async () => {
|
||||
console.log("placeholder")
|
||||
})
|
||||
})
|
||||
// beforeAll(() => {
|
||||
// globalThis.__BLITZ_SESSION_COOKIE_PREFIX = "qm-test-cookie-prefix"
|
||||
// globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
// })
|
||||
|
||||
// describe("useQuery", () => {
|
||||
// const setupHook = (
|
||||
// params: any,
|
||||
// queryFn: (...args: any) => any,
|
||||
// options: Parameters<typeof useQuery>[2] = {} as any,
|
||||
// ): [{data?: any; setQueryData?: any}, Function] => {
|
||||
// let res = {}
|
||||
// function TestHarness() {
|
||||
// const [data, {setQueryData}] = useQuery(queryFn, params, {
|
||||
// suspense: true,
|
||||
// ...options,
|
||||
// } as any)
|
||||
// Object.assign(res, {data, setQueryData})
|
||||
// return (
|
||||
// <div id="harness">
|
||||
// <span>{data ? "Ready" : "No data"}</span>
|
||||
// <span>{data}</span>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
// const ui = () => (
|
||||
// <React.Suspense fallback="Loading...">
|
||||
// <TestHarness />
|
||||
// </React.Suspense>
|
||||
// )
|
||||
|
||||
// const {rerender} = render(ui())
|
||||
// return [res, () => rerender(ui())]
|
||||
// }
|
||||
|
||||
// describe('a "query" that converts the string parameter to uppercase', () => {
|
||||
// const upcase = async (args: string) => {
|
||||
// await delay(1000)
|
||||
// return args.toUpperCase()
|
||||
// }
|
||||
// it("should work with Blitz queries", async () => {
|
||||
// const [res] = setupHook("test", buildQueryRpc(upcase))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("Ready")
|
||||
// expect(res.data).toBe("TEST")
|
||||
// })
|
||||
// })
|
||||
|
||||
// it("should be able to change the data with setQueryData", async () => {
|
||||
// const [res] = setupHook("test", buildQueryRpc(upcase))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("Ready")
|
||||
// expect(res.data).toBe("TEST")
|
||||
// res.setQueryData((p: string) => p.substr(1, 2), {refetch: false})
|
||||
// await waitFor(() => screen.getByText("ES"))
|
||||
// })
|
||||
// })
|
||||
|
||||
// it("shouldn't work with regular functions", () => {
|
||||
// console.error = vi.fn()
|
||||
// expect(() => setupHook("test", upcase)).toThrowErrorMatchingSnapshot()
|
||||
// })
|
||||
|
||||
// it("shouldn't work with mutation function", () => {
|
||||
// console.error = vi.fn()
|
||||
// expect(() => setupHook("test", buildMutationRpc(upcase))).toThrowErrorMatchingSnapshot()
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is false", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {enabled: false})
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is undefined", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {enabled: undefined})
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is false and suspense set", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {
|
||||
// enabled: false,
|
||||
// suspense: true,
|
||||
// })
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
// })
|
||||
|
||||
// // it("works with options other than enabled & suspense without type error", () => {
|
||||
// // const queryFn = ((() => true) as unknown) as () => Promise<boolean>
|
||||
// // useQuery(queryFn, undefined, {refetchInterval: 10000})
|
||||
// // })
|
||||
// })
|
||||
|
||||
// describe("useInfiniteQuery", () => {
|
||||
// const setupHook = (
|
||||
// params: (arg?: any) => any,
|
||||
// queryFn: (...args: any) => any,
|
||||
// ): [{data?: any; setQueryData?: any}, Function] => {
|
||||
// let res = {}
|
||||
// function TestHarness() {
|
||||
// // TODO - fix typing
|
||||
// //@ts-ignore
|
||||
// const [groupedData] = useInfiniteQuery(queryFn, params, {
|
||||
// suspense: true,
|
||||
// getNextPageParam: () => {},
|
||||
// })
|
||||
// Object.assign(res, {groupedData})
|
||||
// return (
|
||||
// <div id="harness">
|
||||
// <span>{groupedData ? "Ready" : "No data"}</span>
|
||||
// <div>
|
||||
// {groupedData.map((data: any, i) => (
|
||||
// <div key={i}>{data}</div>
|
||||
// ))}
|
||||
// </div>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
// const ui = () => (
|
||||
// <React.Suspense fallback="Loading...">
|
||||
// <TestHarness />
|
||||
// </React.Suspense>
|
||||
// )
|
||||
|
||||
// const {rerender} = render(ui())
|
||||
// return [res, () => rerender(ui())]
|
||||
// }
|
||||
|
||||
// const getItems = ({id}: {id: number}) => {
|
||||
// if (id === 1) {
|
||||
// return "item1"
|
||||
// } else if (id === 2) {
|
||||
// return "item2"
|
||||
// } else {
|
||||
// throw new Error("No item for this id")
|
||||
// }
|
||||
// }
|
||||
// it("should work", async () => {
|
||||
// setupHook(() => ({id: 1}), buildQueryRpc(getItems))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("item1")
|
||||
// })
|
||||
|
||||
// setupHook(() => ({id: 2}), buildQueryRpc(getItems))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("item2")
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
13
integration-tests/qm/tsconfig.json
Normal file
13
integration-tests/qm/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "@blitzjs/config/tsconfig.nextjs.json",
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../utils/blitz-test-utils.tsx"],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"paths": {
|
||||
"react": ["./node_modules/@types/react"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"baseUrl": "."
|
||||
}
|
||||
12
integration-tests/qm/vitest.config.ts
Normal file
12
integration-tests/qm/vitest.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference types="vitest" />
|
||||
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({
|
||||
// update me
|
||||
target: 'experimental-serverless-trace',
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"@blitzjs/next": "workspace:*",
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"blitz": "workspace:*",
|
||||
"next": "12.1.1",
|
||||
"next": "12.1.6-canary.17",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0"
|
||||
},
|
||||
@@ -20,7 +20,7 @@
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"eslint": "7.32.0",
|
||||
"fs-extra": "10.0.1",
|
||||
|
||||
@@ -143,7 +143,7 @@ describe("RPC", () => {
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
appPort = await findPort()
|
||||
app = await launchApp(appDir, appPort)
|
||||
app = await launchApp(appDir, appPort, {cwd: process.cwd()})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
@@ -162,7 +162,7 @@ describe("RPC", () => {
|
||||
await nextBuild(appDir)
|
||||
mode = "server"
|
||||
appPort = await findPort()
|
||||
app = await nextStart(appDir, appPort)
|
||||
app = await nextStart(appDir, appPort, {cwd: process.cwd()})
|
||||
})
|
||||
afterAll(() => killApp(app))
|
||||
|
||||
@@ -185,7 +185,7 @@ describe("RPC", () => {
|
||||
await nextBuild(appDir)
|
||||
mode = "serverless"
|
||||
appPort = await findPort()
|
||||
app = await nextStart(appDir, appPort)
|
||||
app = await nextStart(appDir, appPort, {cwd: process.cwd()})
|
||||
})
|
||||
afterAll(async () => {
|
||||
await killApp(app)
|
||||
|
||||
2
integration-tests/trailing-slash/.env
Normal file
2
integration-tests/trailing-slash/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ
|
||||
HEADLESS=true
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user