v2.0.0-beta.24
Blitz Toolkit Beta v24
Support for Next 13
Blitz does not require any breaking changes with the major upgrade of Next 12
➔ Next 13
for usage with the pages directory. You can even continue to use the old blitz layout with all your files in app. But you'll need to rename that directory if you want to use the new Next.js app router.
Read More about usage of Blitz Toolkit with Next 13
cadefb8 & 37aeaa7: Support for Next 13 App directory (beta)
From this release, the blitz toolkit will work out of the box with react server components.
Here are the highlights:
- New Blitz Auth Function
getBlitzCtx
to access the auth context in server components - New Blitz Auth Function
useAuthenticatedBlitzContext
to provide authorization utilities for server components - New wrapper
BlitzProvider
to be wrapped in theRootLayout
present in the (root)/layout.ts file. - Overload the
invoke
method to work when called inside a React Server Component
Patch for Next 13.2 Suspense Error
acc07ce: This updates the suspense patch to work with Next.js 13.2+. Hopefully, soon we can stop patching once Next.js catches up with all the other frameworks and properly exposes the onRecoverableError react hook.
🔨 Breaking Changes
Blitz Auth
9529dbd: Introducing a new import path for the Blitz wrapper SecurePassword
to fully decouple the library from @blitzjs/auth
Change to be made
-import {SecurePassword} from "@blitzjs/auth"
+import {SecurePassword} from "@blitzjs/auth/secure-password"
Automatic Upgrade
Automatically upgrade using codemod
(Make sure to git commit before running this command to avoid losing changes)
npx @blitzjs/codemod secure-password
🚀 New Features
6f18cbd: Next Auth Adapter
Blitz now provides an adapter that allows you to use any NextAuth Provider with Blitz session management in any Nextjs application.
Blitz session management gives you a lot more flexibility & control than NextAuth does.
Usage
// src/pages/api/auth/[...nextauth].ts
import { api } from "src/blitz-server"
import { NextAuthAdapter } from "@blitzjs/auth/next-auth"
import GithubProvider from "next-auth/providers/github"
import db, { User } from "db"
import { Role } from "types"
// Has to be defined separately for `profile` to be correctly typed below
const providers = [
GithubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
}),
]
export default api(
NextAuthAdapter({
successRedirectUrl: "/",
errorRedirectUrl: "/error",
providers,
callback: async (user, account, profile, session) => {
...
},
})
)
ea7561b: Blitz Generator Overhaul
The Blitz generator has been completely overhauled to be more flexible, customizable and easier to use.
Credits
The comes as a cumulative effort from the work started by @maastrich in #2134 then continued and enhanced by @roesh in #2679 and finally fixed and polished by @siddhsuresh in #3869 .
Changes/Features
- Model Fields can now be specified in the generator command
> blitz generate model [fieldName]:[type]:[attribute]
Usage
> blitz generate all project name
> blitz generate all project name:string description:string? active:boolean
# with parent
> blitz generate model task \
name \
completed:boolean:default=false \
belongsTo:project?
-
The generate command can also be run multiple times to add more fields to the model. The generator will then mention the changes that will be made to the model and ask for confirmation before proceeding.
-
ea7561b: New
schema.ts
file will be generated with the requiredzod
schemas that can be used independently with the mutations, queries and components.
This fixes the problem of not being able to import the schemas defined in the mutations due to the RPC compilation
Security Fixes
6e88a84: Fixed security vulnerabilities in passport-adapter by upgrading passport and jsonwebtoken.
Testing Utility Fixes
cadefb8: Fix failing tests due to the error NextRouter is not mounted in next 13 blitz apps.
Template Fixes
- e228ba5: Fix a type error in reset password templates.
- 430f0b5: For new applications, update Prisma (prisma and @prisma/client) from 4.6.0 to 4.6.1 to solve
enum
issue with postgresql Prisma 4.6.0 drops and recreates enum field when runningdb
push even if the field has not changed prisma/prisma#16180
Credits
This release was made possible by the following contributors:
@flybayer, @siddhsuresh, @noxify, @tordans, @Vandivier, @exKAZUu