Skip to content

Commit

Permalink
new blitz app starter (#4146)
Browse files Browse the repository at this point in the history
* new blitz app starter

* tanstack form first time working

* complete app template

* re-arrange generator folders

* add app router as recomended

* upgrade to next 13.5.2 and update location of internal function

* Create lucky-teachers-sleep.md

* fix bootupMarkers

* fix issues with qm integration test

* Update integration-tests/utils/next-test-utils.ts

* next.js generated stuff

* Update .changeset/lucky-teachers-sleep.md

* remove unnecessary next lints to the integration-tests

* Update main.yml

* Revert "remove unnecessary next lints to the integration-tests"

This reverts commit 3226b2e.

* fix starter with tanstack form

* make changes to the generator

* mske final changes

* pnpm lock fix

* more changes

* add logging to rsc invoke and decouple auth from rpc again

* implement object chaining

* add `onInvokeError` options to catch errors without manual wrapping

* rename `LoggerOptions` to `RpcLoggerOptions`

* spacing

* fix error typed to `any`

* update class code

* tests working again

* add last test case proving working modal of roles

* Create moody-pandas-do.md

* Apply suggestions from code review

* move app -> `src/app`

* move from auth -> (auth) directory structure

* review 1 fixes

* missing change from auth -> (auth) change

* review 2: more fixes and match old behaviour

* pnpm lock fix

* add new pages to the `pathsToMove` array

* remove submodule

* remove changelog from the template

* fix name of .env

* match readme

* march prisma schema

* match package.json

* match blitz-client and blitz-server files

* remove vercel logo

* remove `next13`

* upgrade next and add husky

* fix build error

* Create poor-bikes-wait.md

* Revert "remove `next13`"

This reverts commit c0d7f54.

* remove next13

* re-add next 13 that exists in main

* Apply suggestions from code review

* pnpm lock

* improvements to the template

* fix location of imports in `reset-password` page

* Update packages/blitz/src/cli/commands/new.ts

Co-authored-by: Tobias <[email protected]>

* Update packages/generator/templates/app/src/pages/api/rpc/blitzrpcroute.ts

Co-authored-by: Tobias <[email protected]>

* fix auth -> (auth)

* Update packages/generator/templates/app/src/app/layout.tsx

Co-authored-by: Tobias <[email protected]>

* Apply suggestions from code review

Co-authored-by: Tobias <[email protected]>

* abstact forms as client compoennts and pages as rscs

* re-add proper singup mutation

* remove console.log

* fix additonal forms

* pnpm lock fix

* fix missing ,

* Add project package manager to postInstallSteps

* add husky

* move to devDeps

* add preview email

* remove extra components folder

* add 800px as maximum of body size

* remove auth from reset-password url

* fix non-existant compoennts

* pnpm

* fix favicon

* package.json fixes

* revert to `latest`

* move to `devDeps`

* add display names

* make it a template

* new route generator

* fidnally got it working

* add `isAppDir` check

* should be the final changes

* fix

* fix import error

* revert

* make zod optional when needed

* fix tests

* fix nullable issue

* Update packages/blitz-auth/src/server/auth-sessions.ts

* new folder structure

---------

Co-authored-by: Tobias <[email protected]>
  • Loading branch information
siddhsuresh and tordans authored Jan 2, 2024
1 parent b84c5be commit 6d5f9ef
Show file tree
Hide file tree
Showing 159 changed files with 2,973 additions and 330 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-bikes-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/generator": patch
---

new blitz app starter
4 changes: 3 additions & 1 deletion .changeset/sixty-rockets-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Now we can configure Blitz RPC in the following way,

In your `[[...blitz]].ts` api file you can see the following settings

```ts
logging?: {
/**
Expand All @@ -29,6 +30,7 @@ logging?: {
disablelevel?: "debug" | "info"
}
```

```ts
import { rpcHandler } from "@blitzjs/rpc"
import { api } from "src/blitz-server"
Expand All @@ -48,6 +50,7 @@ export default api(
```

Example:

```ts
export default api(
rpcHandler({
Expand All @@ -65,4 +68,3 @@ export default api(
```

This is enable verbose blitz rpc logging for all resolvers except the resolvers `getCurrentUser` and others mentioned in the `blockList`

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useAuthenticatedBlitzContext} from "../../src/blitz-server"
import {useAuthenticatedBlitzContext} from "../../blitz-server"

export default async function RootLayout({children}: {children: React.ReactNode}) {
await useAuthenticatedBlitzContext({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"

import {LoginForm} from "../../../src/auth/components/LoginForm"
import {LoginForm} from "../../../auth/components/LoginForm"
import {useRouter} from "next/navigation"
import {useSearchParams} from "next/navigation"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"

import {useRouter} from "next/navigation"
import SignupForm from "../../../src/auth/components/SignupForm"
import SignupForm from "../../../auth/components/SignupForm"

const SignUp = () => {
const router = useRouter()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "src/styles/globals.css"
import {BlitzProvider} from "../src/blitz-client"
import {BlitzProvider} from "../blitz-client"
import styles from "src/styles/Home.module.css"

export default function RootLayout({children}: {children: React.ReactNode}) {
Expand Down
4 changes: 2 additions & 2 deletions apps/next13/app/page.tsx → apps/next13/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Link from "next/link"
import styles from "src/styles/Home.module.css"
import Test from "./react-query"
import {invoke, useAuthenticatedBlitzContext} from "../src/blitz-server"
import getCurrentUser from "../src/users/queries/getCurrentUser"
import {invoke, useAuthenticatedBlitzContext} from "../blitz-server"
import getCurrentUser from "../users/queries/getCurrentUser"

export default async function Home() {
await useAuthenticatedBlitzContext({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client"

import {useQuery, useMutation} from "@blitzjs/rpc"
import logout from "../src/auth/mutations/logout"
import getCurrentUser from "../src/users/queries/getCurrentUser"
import logout from "../auth/mutations/logout"
import getCurrentUser from "../users/queries/getCurrentUser"
import {useTransition} from "react"
import {useRouter} from "next/navigation"

Expand Down
7 changes: 3 additions & 4 deletions apps/next13/src/auth/mutations/signup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import db from "../../../prisma"
// import {SecurePassword} from "@blitzjs/auth"
import {SecurePassword} from "@blitzjs/auth/secure-password"

export default async function signup(input: {password: string; email: string}, ctx: any) {
const blitzContext = ctx
// const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password")
const hashedPassword = (input.password as string) || "test-password"
const email = (input.email as string) || "test" + Math.random() + "@test.com"
const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password")
const email = input.email
const user = await db.user.create({
data: {email, hashedPassword},
})
Expand Down
7 changes: 6 additions & 1 deletion apps/toolkit-app/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { api } from "src/blitz-server"
import GithubProvider from "next-auth/providers/github"
import { NextAuthAdapter } from "@blitzjs/auth/next-auth"
import EmailProvider from "next-auth/providers/email"
import { NextAuthAdapter, BlitzNextAuthOptions } from "@blitzjs/auth/next-auth"
import db, { User } from "db"
import { Role } from "types"

Expand All @@ -10,6 +11,10 @@ const providers = [
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
}),
EmailProvider({
from: process.env.GITHUB_CLIENT_ID as string,
server: process.env.GITHUB_CLIENT_SECRET as string,
}),
]

export default api(
Expand Down
1 change: 0 additions & 1 deletion apps/toolkit-app/src/pages/auth/reset-password.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect, useState } from "react"
import Layout from "src/core/layouts/Layout"
import { LabeledTextField } from "src/core/components/LabeledTextField"
import { Form, FORM_ERROR } from "src/core/components/Form"
Expand Down
4 changes: 2 additions & 2 deletions apps/toolkit-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const UserInfo = () => {
} else {
return (
<>
<Link href={"/signup"} className={styles.button}>
<Link href={"/auth/signup"} className={styles.button}>
<strong>Sign Up</strong>
</Link>
<Link href={"/login"} className={styles.loginButton}>
<Link href={"/auth/login"} className={styles.loginButton}>
<strong>Login</strong>
</Link>
<Link href="/api/auth/github/login" passHref legacyBehavior>
Expand Down
32 changes: 0 additions & 32 deletions apps/toolkit-app/test/index.test.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions apps/toolkit-app/test/setup.ts

This file was deleted.

106 changes: 0 additions & 106 deletions apps/toolkit-app/test/utils.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions packages/blitz-rpc/src/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createServerPlugin,
} from "blitz"
import {invoke} from "./invoke"
import {RpcLogger} from "../rpc-logger"

export type RpcLoggerOptions = {
/**
Expand Down Expand Up @@ -47,6 +48,9 @@ export const RpcServerPlugin = createServerPlugin((options: RpcPluginOptions) =>
} catch (error) {
if (options.onInvokeError) {
options.onInvokeError(error)
} else {
const rpcLogger = new RpcLogger((queryFn as any)._resolverName, options.logging)
rpcLogger.error(error)
}
throw error
}
Expand Down
17 changes: 11 additions & 6 deletions packages/blitz/src/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ import {CliCommand} from "../index"
import prompts from "prompts"
import {
capitalize,
pluralCamel,
pluralPascal,
singleCamel,
singlePascal,
uncapitalize,
PageGenerator,
FormGenerator,
QueriesGenerator,
MutationGenerator,
MutationsGenerator,
RouteGenerator,
ModelGenerator,
QueryGenerator,
ValidationsGenerator,
Expand All @@ -23,6 +20,7 @@ import {
customTemplatesBlitzConfig,
} from "@blitzjs/generator"
import {log} from "../../logging"
import fs from "fs-extra"

const getIsTypeScript = async () =>
require("fs").existsSync(require("path").join(process.cwd(), "tsconfig.json"))
Expand Down Expand Up @@ -72,18 +70,25 @@ const createCustomTemplates = async () => {
process.exit(0)
}

const nextAppDirectory = fs.existsSync(require("path").join(process.cwd(), "src/app/layout.tsx"))
? "app"
: "pages"

const generatorMap = {
[ResourceType.All]: [
PageGenerator,
FormGenerator,
QueriesGenerator,
MutationsGenerator,
ValidationsGenerator,
ModelGenerator,
nextAppDirectory === "app" ? RouteGenerator : PageGenerator,
],
[ResourceType.Crud]: [MutationsGenerator, QueriesGenerator, ValidationsGenerator],
[ResourceType.Model]: [ModelGenerator],
[ResourceType.Pages]: [PageGenerator, FormGenerator],
[ResourceType.Pages]: [
FormGenerator,
nextAppDirectory === "app" ? RouteGenerator : PageGenerator,
],
[ResourceType.Queries]: [QueriesGenerator],
[ResourceType.Query]: [QueryGenerator],
[ResourceType.Mutations]: [MutationsGenerator, ValidationsGenerator],
Expand Down
Loading

0 comments on commit 6d5f9ef

Please sign in to comment.