-
-
Notifications
You must be signed in to change notification settings - Fork 818
Open
Labels
Description
What is the problem?
app router template, config not work
export const cliConfig: BlitzCliConfig = {
customTemplates: "src/templates",
}
Paste all relevant code snippets here:
// src/app/blitz-server.ts
import type { BlitzCliConfig } from "blitz";
import {setupBlitzServer} from "@blitzjs/next"
import {AuthServerPlugin, PrismaStorage, simpleRolesIsAuthorized} from "@blitzjs/auth"
import db from "db"
import {BlitzLogger} from "blitz"
import {RpcServerPlugin} from "@blitzjs/rpc"
import {authConfig} from "./blitz-auth-config"
const {api, getBlitzContext, useAuthenticatedBlitzContext, invoke,withBlitzAuth} = setupBlitzServer({
plugins: [
AuthServerPlugin({
...authConfig,
storage: PrismaStorage(db),
isAuthorized: simpleRolesIsAuthorized,
}),
RpcServerPlugin({}),
],
logger: BlitzLogger({}),
})
export {api, getBlitzContext, useAuthenticatedBlitzContext, invoke,withBlitzAuth}
export const cliConfig: BlitzCliConfig = {
customTemplates: "src/templates"
};generated file
// src/app/notes/new/page.tsx
import { Metadata } from "next";
import { Suspense } from "react";
import { New__ModelName } from "../components/NewNote";
export const metadata: Metadata = {
title: "New Project",
description: "Create a new project",
};
export default function Page() {
return (
<div>
<h1>Create New Project</h1>
<Suspense fallback={<div>Loading...</div>}>
<New__ModelName />
</Suspense>
</div>
);
}expected use template, but blitz/packages/generator/templates/route/new/page.tsx at main · blitz-js/blitz · GitHub
// src/templates/page/new.tsx
import {Routes} from '@blitzjs/next'
if (process.env.parentModel) {
import Link from 'next/link'
import {useParam} from '@blitzjs/next'
import { useRouter } from "next/router"
import {useMutation} from '@blitzjs/rpc'
} else {
import Link from 'next/link'
import { useRouter } from "next/router"
import {useMutation} from '@blitzjs/rpc'
}
import Layout from "src/core/layouts/Layout"
import {Create__ModelName__Schema} from "src/__modelNamesPath__/schemas"
import create__ModelName__ from "src/__modelNamesPath__/mutations/create__ModelName__"
import {__ModelName__Form, FORM_ERROR} from "src/__modelNamesPath__/components/__ModelName__Form"
import { Suspense } from 'react'
const New__ModelName__Page = () => {
const router = useRouter()
if (process.env.parentModel) {
const __parentModelId__ = useParam("__parentModelId__", "number")
}
const [create__ModelName__Mutation] = useMutation(create__ModelName__)
return (
<Layout title={"Create New __ModelName__"}>
<h1>Create New __ModelName__</h1>
<Suspense fallback={<div>Loading...</div>}>
<__ModelName__Form
submitText="Create __ModelName__"
schema={Create__ModelName__Schema}
// initialValues={{}}
onSubmit={async (values) => {
try {
const __modelName__ = await create__ModelName__Mutation(
process.env.parentModel
? {...values, __parentModelId__: __parentModelId__!}
: values,
)
await router.push(
process.env.parentModel
? Routes.Show__ModelName__Page({ __parentModelId__: __parentModelId__!, __modelId__: __modelName__.id })
: Routes.Show__ModelName__Page({ __modelId__: __modelName__.id }),
)
} catch (error: any) {
console.error(error)
return {
[FORM_ERROR]: error.toString(),
}
}
}}
/>
</Suspense>
<p>
<if condition="parentModel">
<Link href={Routes.__ModelNames__Page({ __parentModelId__: __parentModelId__! })}>
__ModelNames__
</Link>
<else>
<Link href={Routes.__ModelNames__Page()}>
__ModelNames__
</Link>
</else>
</if>
</p>
</Layout>
)
}
New__ModelName__Page.authenticate = true
export default New__ModelName__PageWhat are detailed steps to reproduce this?
-> % blitz new blitz-app-router
Loaded env from /Users/zenochan/Zeno/projects/2509_zeno-station/.env
? Pick your new app template › - Use arrow-keys. Return to submit.
❯ App Router – Full Setup: includes DB and auth (Recommended)
-> % blitz g custom-templates
-> % blitz g pages note title:string
Run blitz -v and paste the output here:
Blitz version: 3.0.2 (global)
Blitz version: 3.0.2 (local)
macOS Sequoia | darwin-x64 | Node: v20.15.0
Package manager: npm
System:
OS: macOS 15.6.1
CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Memory: 1.73 GB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
Yarn: 4.9.4 - ~/.nvm/versions/node/v20.15.0/bin/yarn
npm: 10.8.1 - ~/.nvm/versions/node/v20.15.0/bin/npm
npmPackages:
@blitzjs/auth: 3.0.2 => 3.0.2
@blitzjs/next: 3.0.2 => 3.0.2
@blitzjs/rpc: 3.0.2 => 3.0.2
@prisma/client: 5.4.2 => 5.4.2
blitz: 3.0.2 => 3.0.2
next: 15.0.1 => 15.0.1
prisma: 5.4.2 => 5.4.2
react: 19.0.0 => 19.0.0
react-dom: 19.0.0 => 19.0.0
typescript: ^4.8.4 => 4.9.5