1
0
mirror of synced 2026-02-03 18:01:02 -05:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Dillon Raphael
653dac8a68 fix routes for finding blitz in node_modules 2022-08-02 14:16:52 -04:00
Aleksandra
065db256d7 Update generator templates to use resolver function (#3652) 2022-08-02 14:49:31 +02:00
6 changed files with 42 additions and 58 deletions

View File

@@ -0,0 +1,5 @@
---
"@blitzjs/generator": patch
---
Update new app templates to use blitz-rpc's resolver function

View File

@@ -12,17 +12,7 @@ const stat = promisify(fs.stat)
const debug = require("debug")("blitz:postinstall")
const isInBlitzMonorepo = fs.existsSync(path.join(__dirname, "../../blitz-next"))
let isInstalledGlobally = isInBlitzMonorepo ? false : true // default
try {
const maybeGlobalBlitzPath = resolveFrom(__dirname, "blitz")
const localBlitzPath = resolveFrom.silent(process.cwd(), "blitz/dist/index.cjs")
isInstalledGlobally = maybeGlobalBlitzPath !== localBlitzPath
} catch (error) {
// noop
}
// todo: we should reuse `findNodeModulesRoot` from /nextjs/packages/next/build/routes.ts
async function findNodeModulesRoot(src) {
let root
if (isInBlitzMonorepo) {
@@ -105,11 +95,10 @@ function codegen() {
try {
const packagePath = require.resolve("blitz/package.json")
if (packagePath) {
const blitzPkg = require.resolve("blitz/dist/index.cjs")
if (blitzPkg.includes(".pnpm")) {
return path.join(blitzPkg, "../../../../../../blitz/dist/index.cjs")
if (packagePath.includes(".pnpm")) {
return path.join(packagePath, "../../blitz/dist/index.cjs")
} else {
return path.join(blitzPkg)
return path.join(packagePath, "../dist/index.cjs")
}
}
} catch (e) {
@@ -337,6 +326,4 @@ function codegen() {
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR'
}
// if (!isInstalledGlobally) {
codegen()
// }

View File

@@ -1,9 +1,9 @@
import { NotFoundError, AuthenticationError } from "blitz"
import { resolver } from "@blitzjs/rpc"
import { SecurePassword } from "@blitzjs/auth"
import db from "db"
import { authenticateUser } from "./login"
import { ChangePassword } from "../validations"
import { resolver } from "@blitzjs/rpc"
import { SecurePassword } from "@blitzjs/auth"
export default resolver.pipe(
resolver.zod(ChangePassword),

View File

@@ -1,4 +1,5 @@
import { SecurePassword, hash256 } from "@blitzjs/auth"
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { ResetPassword } from "../validations"
import login from "./login"
@@ -8,10 +9,9 @@ export class ResetPasswordError extends Error {
message = "Reset password link is invalid or it has expired."
}
export default async function resetPassword(input, ctx) {
ResetPassword.parse(input)
export default resolver.pipe(resolver.zod(ResetPassword), async ({ password, token }, ctx) => {
// 1. Try to find this token in the database
const hashedToken = hash256(input.token)
const hashedToken = hash256(token)
const possibleToken = await db.token.findFirst({
where: { hashedToken, type: "RESET_PASSWORD" },
include: { user: true },
@@ -32,7 +32,7 @@ export default async function resetPassword(input, ctx) {
}
// 5. Since token is valid, now we can update the user's password
const hashedPassword = await SecurePassword.hash(input.password.trim())
const hashedPassword = await SecurePassword.hash(password.trim())
const user = await db.user.update({
where: { id: savedToken.userId },
data: { hashedPassword },
@@ -42,7 +42,7 @@ export default async function resetPassword(input, ctx) {
await db.session.deleteMany({ where: { userId: user.id } })
// 7. Now log the user in with the new credentials
await login({ email: user.email, password: input.password }, ctx)
await login({ email: user.email, password }, ctx)
return true
}
})

View File

@@ -1,21 +1,16 @@
import db from "db"
import { SecurePassword } from "@blitzjs/auth"
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { Role } from "types"
import { Signup } from "../validations"
export default async function signup(input, ctx) {
const blitzContext = ctx
const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password")
const email = (input.email as string) || "test" + Math.random() + "@test.com"
export default resolver.pipe(resolver.zod(Signup), async ({ email, password }, ctx) => {
const hashedPassword = await SecurePassword.hash(password.trim())
const user = await db.user.create({
data: { email, hashedPassword, role: "user" },
data: { email: email.toLowerCase().trim(), hashedPassword, role: "USER" },
select: { id: true, name: true, email: true, role: true },
})
await blitzContext.session.$create({
userId: user.id,
role: user.role as Role,
})
return { userId: blitzContext.session.userId, ...user, email: input.email }
}
await ctx.session.$create({ userId: user.id, role: user.role as Role })
return user
})

37
pnpm-lock.yaml generated
View File

@@ -49,7 +49,7 @@ importers:
"@types/preview-email": 2.0.1
"@types/react": 18.0.1
"@typescript-eslint/eslint-plugin": 5.9.1
blitz: workspace:2.0.0-alpha.64
blitz: workspace:2.0.0-alpha.65
eslint: 7.32.0
eslint-config-next: 12.2.0
eslint-config-prettier: 8.5.0
@@ -475,8 +475,8 @@ importers:
packages/blitz:
specifiers:
"@blitzjs/config": workspace:2.0.0-alpha.64
"@blitzjs/generator": 2.0.0-alpha.64
"@blitzjs/config": workspace:2.0.0-alpha.65
"@blitzjs/generator": 2.0.0-alpha.65
"@types/cookie": 0.4.1
"@types/cross-spawn": 6.0.2
"@types/debug": 4.1.7
@@ -584,7 +584,7 @@ importers:
packages/blitz-auth:
specifiers:
"@blitzjs/config": workspace:2.0.0-alpha.64
"@blitzjs/config": workspace:2.0.0-alpha.65
"@testing-library/react": 13.0.0
"@testing-library/react-hooks": 7.0.2
"@types/b64-lite": 1.3.0
@@ -598,7 +598,7 @@ importers:
"@types/secure-password": 3.1.1
b64-lite: 1.4.0
bad-behavior: 1.0.1
blitz: 2.0.0-alpha.64
blitz: 2.0.0-alpha.65
cookie: 0.4.1
cookie-session: 2.0.0
debug: 4.3.3
@@ -649,8 +649,8 @@ importers:
packages/blitz-next:
specifiers:
"@blitzjs/config": workspace:2.0.0-alpha.64
"@blitzjs/rpc": 2.0.0-alpha.64
"@blitzjs/config": workspace:2.0.0-alpha.65
"@blitzjs/rpc": 2.0.0-alpha.65
"@tanstack/react-query": 4.0.10
"@testing-library/dom": 8.13.0
"@testing-library/jest-dom": 5.16.3
@@ -662,7 +662,7 @@ importers:
"@types/react": 18.0.1
"@types/react-dom": 17.0.14
"@types/testing-library__react-hooks": 4.0.0
blitz: 2.0.0-alpha.64
blitz: 2.0.0-alpha.65
cross-spawn: 7.0.3
debug: 4.3.3
find-up: 4.1.0
@@ -710,15 +710,15 @@ importers:
packages/blitz-rpc:
specifiers:
"@blitzjs/auth": 2.0.0-alpha.64
"@blitzjs/config": workspace:2.0.0-alpha.64
"@blitzjs/auth": 2.0.0-alpha.65
"@blitzjs/config": workspace:2.0.0-alpha.65
"@tanstack/react-query": 4.0.10
"@types/debug": 4.1.7
"@types/react": 18.0.1
"@types/react-dom": 17.0.14
b64-lite: 1.4.0
bad-behavior: 1.0.1
blitz: 2.0.0-alpha.64
blitz: 2.0.0-alpha.65
chalk: ^4.1.0
debug: 4.3.3
next: 12.2.0
@@ -759,12 +759,12 @@ importers:
"@babel/plugin-syntax-typescript": 7.17.12
"@babel/preset-env": 7.12.10
"@blitzjs/config": workspace:*
"@blitzjs/generator": 2.0.0-alpha.64
"@blitzjs/generator": 2.0.0-alpha.65
"@types/jscodeshift": 0.11.2
"@types/node": 17.0.16
arg: 5.0.1
ast-types: 0.14.2
blitz: 2.0.0-alpha.64
blitz: 2.0.0-alpha.65
chalk: ^4.1.0
cross-spawn: 7.0.3
debug: 4.3.3
@@ -819,7 +819,7 @@ importers:
"@babel/plugin-transform-typescript": 7.12.1
"@babel/preset-env": 7.12.10
"@babel/types": 7.12.10
"@blitzjs/config": 2.0.0-alpha.64
"@blitzjs/config": 2.0.0-alpha.65
"@juanm04/cpx": 2.0.1
"@mrleebo/prisma-ast": 0.2.6
"@types/babel__core": 7.1.19
@@ -910,7 +910,7 @@ importers:
packages/pkg-template:
specifiers:
"@blitzjs/config": 2.0.0-alpha.64
"@blitzjs/config": 2.0.0-alpha.65
"@types/react": 18.0.1
"@types/react-dom": 17.0.14
"@typescript-eslint/eslint-plugin": 5.9.1
@@ -4917,7 +4917,6 @@ packages:
typescript: 4.6.3
transitivePeerDependencies:
- supports-color
dev: false
/@typescript-eslint/experimental-utils/5.28.0_hrkuebk64jiu2ut2d2sm4oylnu:
resolution:
@@ -8572,7 +8571,6 @@ packages:
transitivePeerDependencies:
- eslint-import-resolver-webpack
- supports-color
dev: false
/eslint-config-next/12.2.3_hrkuebk64jiu2ut2d2sm4oylnu:
resolution:
@@ -8610,7 +8608,6 @@ packages:
hasBin: true
peerDependencies:
eslint: ">=7.0.0"
dev: false
/eslint-config-prettier/8.5.0_eslint@7.32.0:
resolution:
@@ -11127,7 +11124,7 @@ packages:
pretty-format: 27.5.1
slash: 3.0.0
strip-json-comments: 3.1.1
ts-node: 10.7.0_typescript@4.6.3
ts-node: 10.7.0_fxg3r7oju3tntkxsvleuiot4fa
transitivePeerDependencies:
- bufferutil
- canvas
@@ -16255,7 +16252,6 @@ packages:
typescript: 4.6.3
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
dev: false
/ts-node/10.7.0_typescript@4.6.3:
resolution:
@@ -16288,6 +16284,7 @@ packages:
typescript: 4.6.3
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
dev: false
/tsconfig-paths/3.14.1:
resolution: