### Install @blitzjs/rpc Plugin
Source: https://blitzjs.com/docs/rpc-setup
Instructions for installing the @blitzjs/rpc plugin using npm, yarn, or pnpm.
```bash
npm i @blitzjs/rpc # yarn add @blitzjs/rpc # pnpm add @blitzjs/rpc
```
--------------------------------
### Start Package Server
Source: https://blitzjs.com/docs/contributing
Starts the package server, which is essential for any package or example development within the Blitz.js project.
```bash
pnpm dev
```
--------------------------------
### Install Project Dependencies
Source: https://blitzjs.com/docs/contributing
Installs all necessary project dependencies using the pnpm package manager.
```bash
pnpm i
```
--------------------------------
### Install a Blitz Recipe
Source: https://blitzjs.com/docs/using-recipes
Demonstrates how to install a Blitz Recipe, such as Tailwind CSS, using the `blitz install` command. This command handles dependency installation and configuration file creation.
```bash
> blitz install tailwind
✅ Installed 2 dependencies
✅ Successfully created postcss.config.js, tailwind.config.js
✅ Successfully created app/styles/button.css, app/styles/index.css
✅ Modified 1 file: app/pages/_app.tsx
🎉 The recipe for Tailwind CSS completed successfully! Its functionality is now fully configured in your Blitz app.
```
--------------------------------
### Install Prisma and Initialize Client
Source: https://blitzjs.com/docs/blitz-auth-with-next
Installs Prisma and its client, then initializes a new Prisma client with SQLite as the data source provider.
```bash
yarn add prisma @prisma/client
```
```bash
yarn prisma init --datasource-provider sqlite
```
--------------------------------
### Blitz.js Server Setup
Source: https://blitzjs.com/docs/usage-next-13
Sets up the Blitz.js server, exporting necessary utilities like useAuthenticatedBlitzContext.
```typescript
// src/blitz-server.ts
export const { ... , useAuthenticatedBlitzContext} = setupBlitzServer({
...
})
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/getting-started
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### Install @blitzjs/auth Plugin
Source: https://blitzjs.com/docs/auth-setup
Installs the @blitzjs/auth plugin using npm, yarn, or pnpm.
```bash
npm i @blitzjs/auth
yarn add @blitzjs/auth
pnpm add @blitzjs/auth
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/get-started
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### Vitest Configuration Example
Source: https://blitzjs.com/docs/testing
Example of a vitest.config.ts file for customizing Vitest settings, including plugins, global setup, and coverage reporters.
```typescript
// vitest.config.ts
import { loadEnvConfig } from "@next/env"
import { defineConfig } from "vitest/config"
import react from "@vitejs/plugin-react"
import tsconfigPaths from "vite-tsconfig-paths"
const projectDir = process.cwd()
loadEnvConfig(projectDir)
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), tsconfigPaths()],
test: {
dir: "./",
globals: true,
setupFiles: "./test/setup.ts",
coverage: {
reporter: ["text", "json", "html"],
},
},
})
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/resolver-utilities
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### BlitzProvider Setup for Next.js App Router
Source: https://blitzjs.com/docs/usage-next-13
Demonstrates the setup of the BlitzProvider in the `blitz-client.ts` file, including necessary plugins like AuthClientPlugin and BlitzRpcPlugin. Also shows how to import and use BlitzProvider in the root layout file.
```typescript
// src/blitz-client.ts
"use client"
import {AuthClientPlugin} from "@blitzjs/auth"
import {setupBlitzClient} from "@blitzjs/next"
import {BlitzRpcPlugin} from "@blitzjs/rpc"
import { authConfig } from './blitz-auth-config'
export const {withBlitz, BlitzProvider} = setupBlitzClient({
plugins: [
AuthClientPlugin(authConfig),
BlitzRpcPlugin({}),
],
})
```
```typescript
// src/blitz-auth-config.ts
import { AuthPluginClientOptions } from '@blitzjs/auth'
export const authConfig: AuthPluginClientOptions = {
cookiePrefix: "blitz-auth-with-next-app",
}
```
```typescript
// src/layout.ts
import { BlitzProvider } from "src/blitz-client"
export default function RootLayout({children}: {children: React.ReactNode}) {
return (
...
...
)
}
```
--------------------------------
### Client Setup for @blitzjs/rpc
Source: https://blitzjs.com/docs/rpc-setup
Configures the Blitz.js client with the RPC plugin. Allows for customization of react-query options.
```typescript
import { setupClient } from "@blitzjs/next"
import { BlitzRpcPlugin } from "@blitzjs/rpc"
const { withBlitz } = setupClient({
plugins: [BlitzRpcPlugin()],
})
export { withBlitz }
```
```typescript
import { setupClient } from "@blitzjs/next"
import { BlitzRpcPlugin } from "@blitzjs/rpc"
const { withBlitz } = setupClient({
plugins: [
BlitzRpcPlugin({
reactQueryOptions: {
queries: {
staleTime: 7000,
},
},
}),
],
})
export { withBlitz }
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/auth-utils
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### Start Blitz.js Development Server
Source: https://blitzjs.com/docs/tutorial
Command to start the development server for a Blitz.js application. It compiles the application and makes it available at http://localhost:3000.
```bash
blitz dev
```
--------------------------------
### Blitz CLI: generate command - example output
Source: https://blitzjs.com/docs/cli-generate
An example demonstrating the files generated by `blitz generate all project`, including pages, components, queries, and mutations.
```bash
blitz generate all project
# Example Output:
app/pages/projects/[projectId]/edit.tsx
app/pages/projects/[projectId].tsx
app/pages/projects/index.tsx
app/pages/projects/new.tsx
app/projects/components/ProjectForm.tsx
app/projects/queries/getProject.ts
app/projects/queries/getProjects.ts
app/projects/mutations/createProject.ts
app/projects/mutations/deleteProject.ts
app/projects/mutations/updateProject.ts
```
--------------------------------
### Server Setup for @blitzjs/rpc
Source: https://blitzjs.com/docs/rpc-setup
Sets up the Blitz.js server with the RPC plugin, allowing for custom error handling and logging configurations.
```typescript
const { invoke } = setupBlitzServer({
plugins: [
// Other plugins
RpcServerPlugin({
logging: {
//logging options
},
onInvokeError(error) {
// Add your custom error handling here
},
}),
],
})
export { invoke }
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/%28/docs/auth-config
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/blitz-auth-with-next/add-auth-logic
Installs the Blitz command-line interface globally. This allows you to create and manage Blitz projects.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### API Setup for @blitzjs/rpc (Pages Router)
Source: https://blitzjs.com/docs/rpc-setup
Configures the RPC API handler for the Pages Router in Blitz.js, integrating with the Blitz server setup.
```typescript
// src/pages/api/rpc/[[...blitz]].ts
import { rpcHandler } from "@blitzjs/rpc"
import { api } from "src/blitz-server"
export default api(rpcHandler({}))
```
--------------------------------
### Blitz Recipes Installation
Source: https://blitzjs.com/docs/why-blitz
Demonstrates how to use Blitz recipes to install and configure various libraries like Tailwind CSS, Chakra UI, and Material UI with single commands.
```bash
blitz install tailwind
blitz install chakra-ui
blitz install material-ui
```
--------------------------------
### Prisma Client Setup
Source: https://blitzjs.com/docs/blitz-auth-with-next
Sets up the Prisma client instance for database interactions in a Blitz.js application.
```typescript
// prisma/index.ts
import { PrismaClient } from "@prisma/client"
export * from "@prisma/client"
const db = new PrismaClient()
export default db
```
--------------------------------
### Install Recipe Dependencies
Source: https://blitzjs.com/docs/writing-recipes
Installs the necessary dependencies for creating a Blitz.js recipe, including `blitz` and `jscodeshift` for file transformations.
```bash
pnpm add blitz jscodeshift @types/jscodeshift
```
--------------------------------
### Install Blitz.js Dependencies
Source: https://blitzjs.com/docs/blitz-auth-with-next
Installs the necessary Blitz.js packages for a Next.js project, including the core blitz package, the Next.js adapter, and the auth plugin.
```bash
yarn add blitz @blitzjs/next @blitzjs/auth
```
--------------------------------
### Install @blitzjs/next
Source: https://blitzjs.com/docs/blitzjs-next
Installs the @blitzjs/next adapter for integrating Blitz.js with Next.js projects. Supports npm, yarn, and pnpm.
```bash
npm i @blitzjs/next
# or
yarn add @blitzjs/next
# or
pnpm add @blitzjs/next
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/index
Installs the Blitz command-line interface globally. Requires Node.js 16 or newer.
```bash
yarn global add blitz
```
```bash
npm install -g blitz
```
--------------------------------
### Start Blitz Production Server
Source: https://blitzjs.com/docs/cli-start
Starts the Blitz production server, acting as a wrapper for the Next CLI to enhance environment variable loading. It loads specific .env files, sets the APP_ENV, and passes arguments to the next build command.
```APIDOC
blitz start
**Alias:** `blitz s`
Starts the Blitz production server.
**Description:**
This command is a thin wrapper over the Next CLI, designed to improve environment variable loading. It performs the following actions:
1. Loads the correct `.env.X` and `.env.X.local` files based on the `-e X` flag (e.g., `-e staging` loads `.env.staging`).
2. Sets `process.env.APP_ENV` to the specified environment name (e.g., `-e staging` sets `APP_ENV=staging`).
3. Passes all other arguments directly to the `next build` command.
**Options:**
| Option | Shorthand | Description | Default |
|-----------|-----------|--------------------------------------------|-----------|
| `--hostname` | `-H` | Set the hostname to use for the server. | `"localhost"` |
| `--port` | `-p` | Set the port for the server to listen on. | `3000` |
| `--inspect` | | Enable the Node.js inspector. | `false` |
| `--env` | `-e` | Set app environment name. Read more. | None |
**Examples:**
Make sure to run `blitz build` before running `blitz start`.
```
blitz start
blitz start -H 127.0.0.1 -p 5632
```
**Related Commands:**
- `blitz dev`
- `blitz build`
```
--------------------------------
### Install Blitz CLI
Source: https://blitzjs.com/docs/cli-overview
Instructions for installing the Blitz CLI globally using npm or Yarn. This allows for on-demand execution of Blitz commands.
```bash
# npm
npm i -g blitz
# Yarn
yarn global add blitz
```
--------------------------------
### Install Blitz Recipe
Source: https://blitzjs.com/docs/cli-install
Installs a Blitz Recipe into your project, supporting official, local, and GitHub-hosted recipes. Recipes can also accept key-value arguments.
```APIDOC
blitz install [name] [--yes] [--env]
Alias: blitz i
Use this command to install a Blitz Recipe into your project. Supports official recipes, custom third-party recipes, local recipes, and GitHub-hosted recipes.
Argument:
name: The name of the recipe to install, a path to a local recipe, or a GitHub repository name.
Options:
--yes, -y: Install the recipe automatically without user confirmation. (default: false)
--env, -e: Set app environment name.
Arguments to recipe:
key=value: Pass arguments to the recipe itself if it accepts them.
Example Output:
> blitz install
? Select a recipe to install …
❯ base-web
bumbag-ui
chakra-ui
emotion
### and more
> blitz install tailwind
✅ Installed 2 dependencies
✅ Successfully created postcss.config.js, tailwind.config.js
✅ Successfully created app/styles/button.css, app/styles/index.css
✅ Modified 1 file: app/pages/_app.tsx
🎉 The recipe for Tailwind CSS completed successfully! Its functionality is now fully configured in your Blitz app.
```
--------------------------------
### Blitz.js Database Seeding Example
Source: https://blitzjs.com/docs/database-seeds
This snippet demonstrates how to create a `db/seeds.ts` file in Blitz.js to populate your database with initial data. It includes a Prisma schema example and the corresponding TypeScript seed file.
```typescript
import db from "./index"
const seed = async () => {
const project = await db.project.create({ data: { name: "FooBar" } })
for (let i = 0; i < 5; i++) {
await db.task.create({
data: {
name: `Task: ${i}`,
project: {
connect: {
id: project.id,
},
},
},
})
}
}
export default seed
```
--------------------------------
### API Setup for @blitzjs/rpc (App Router)
Source: https://blitzjs.com/docs/rpc-setup
Configures the RPC API handler for the App Router in Blitz.js, with options for standalone usage or integration with Blitz Auth.
```typescript
// app/api/rpc/[[...blitz]]/route.ts
import { rpcAppHandler } from "@blitzjs/rpc"
export const { GET, POST, HEAD } = rpcAppHandler()
```
```typescript
// app/api/rpc/[[...blitz]]/route.ts
import { rpcAppHandler } from "@blitzjs/rpc"
import { withBlitzAuth } from "app/blitz-server"
export const { GET, POST, HEAD } = withBlitzAuth(rpcAppHandler())
```
--------------------------------
### Blitz.js API Route Example
Source: https://blitzjs.com/docs/blitzjs-next
Shows how to create a Blitz.js API route using the `api` function from `blitz-server`. This example demonstrates how to handle requests and send JSON responses, including session context.
```typescript
import { api } from "src/blitz-server"
export default api(async (req, res, ctx) => {
res.status(200).json({ userId: ctx?.session.userId })
})
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/getting-started
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/get-started
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Install Chromedriver on Windows
Source: https://blitzjs.com/docs/contributing
Installs Chromedriver on Windows using Chocolatey, required for running integration tests.
```bash
chocolatey install chromedriver
```
--------------------------------
### Install Chromedriver on macOS
Source: https://blitzjs.com/docs/contributing
Installs Chromedriver on macOS using Homebrew, required for running integration tests.
```bash
brew install --cask chromedriver
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/resolver-utilities
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Install macOS Dependencies for sodium-native
Source: https://blitzjs.com/docs/contributing
Installs autoconf and automake on macOS to resolve potential issues with the 'sodium-native' package.
```bash
brew install autoconf automake
```
--------------------------------
### Create and Run a New Blitz App
Source: https://blitzjs.com/docs/index
Creates a new Blitz application, navigates into the project directory, and starts the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Install Postgres on Mac via Homebrew
Source: https://blitzjs.com/docs/postgres
Installs and starts a PostgreSQL server on macOS using the Homebrew package manager.
```bash
brew install postgresql
brew services start postgresql
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/auth-utils
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Blitz CLI Overview
Source: https://blitzjs.com/docs/cli-install
Provides an overview of the Blitz.js CLI commands, including commands for creating new projects, running the development server, building for production, managing Prisma, generating code, and more.
```APIDOC
Blitz CLI Commands:
- blitz new: Creates a new Blitz.js project.
- blitz dev: Runs the Blitz development server.
- blitz start: Builds and starts the Blitz application for production.
- blitz build: Builds the Blitz application for production.
- blitz prisma: Manages Prisma schema and database migrations.
- blitz generate: Generates code scaffolds (e.g., models, RPC endpoints).
- blitz codegen: Generates code based on schema definitions.
- blitz routes: Displays the application's routes.
- blitz console: Opens an interactive Blitz console.
- blitz install: Installs Blitz Recipes.
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/blitz-auth-with-next/add-auth-logic
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Cypress Integration for Blitz.js
Source: https://blitzjs.com/docs/testing
Guidance on integrating Cypress, a front-end testing framework, with your Blitz application for end-to-end testing. Includes setup examples, user creation commands, and test patterns.
```javascript
// Example of a Cypress command for user login (conceptual)
Cypress.Commands.add('login', (email, password) => {
cy.request('POST', '/api/auth/login', {
email,
password
})
.then((response) => {
expect(response.body.success).to.be.true;
// Store token or session info
});
});
// Example of a basic end-to-end test
context('Authentication', () => {
it('should allow a user to log in', () => {
cy.login('test@example.com', 'password123');
cy.url().should('include', '/dashboard');
});
});
// Refer to the Blitz.js example for a complete Cypress setup.
```
--------------------------------
### Create a New Blitz App
Source: https://blitzjs.com/docs/%28/docs/auth-config
Steps to create a new Blitz.js application, navigate into the project directory, and start the development server.
```bash
blitz new myAppName
cd myAppName
blitz dev
```
--------------------------------
### Blitz Auth Redis Session Storage Example
Source: https://blitzjs.com/docs/blitz-auth-with-next
Demonstrates setting up Blitz.js authentication with Redis for session management. Includes functions for creating, getting, updating, and deleting sessions using ioredis.
```typescript
import IoRedis from "ioredis"
import { setupBlitz } from "@blitzjs/next"
import {
AuthServerPlugin,
simpleRolesIsAuthorized,
SessionModel,
Session,
} from "@blitzjs/auth"
const dbs: Record = {
default: undefined,
auth: undefined,
}
export function getRedis(): IoRedis.Redis {
if (dbs.default) {
return dbs.default
}
return (dbs.default = createRedis(0))
}
export function getAuthRedis(): IoRedis.Redis {
if (dbs.auth) {
return dbs.auth
}
return (dbs.auth = createRedis(1))
}
export function createRedis(db: number) {
return new IoRedis({
port: 6379,
host: "localhost",
keepAlive: 60,
keyPrefix: "auth:",
db,
})
}
const { gSSP, gSP, api } = setupBlitz({
plugins: [
AuthServerPlugin({
cookiePrefix: "blitz-app-prefix",
isAuthorized: simpleRolesIsAuthorized,
storage: {
createSession: (session: SessionModel): Promise => {
return new Promise((resolve, reject) => {
getAuthRedis().set(
`token:${session.handle}`,
JSON.stringify(session),
(err) => {
if (err) {
reject(err)
} else {
getAuthRedis().lpush(
`device:${String(session.userId)}`,
session.handle
)
resolve(session)
}
}
)
})
},
deleteSession(handle: string): Promise {
return new Promise((resolve, reject) => {
getAuthRedis()
.get(`token:${handle}`)
.then((result) => {
if (result) {
const session = JSON.parse(result) as SessionModel
const userId = session.userId as unknown as string
getAuthRedis().lrem(userId, 0, handle).catch(reject)
}
getAuthRedis().del(handle, (err) => {
if (err) {
reject(err)
} else {
resolve({ handle })
}
})
})
})
},
getSession(handle: string): Promise {
return new Promise((resolve, reject) => {
getAuthRedis()
.get(`token:${handle}`)
.then((data: string | null) => {
if (data) {
resolve(JSON.parse(data))
} else {
resolve(null)
}
})
.catch(reject)
})
},
getSessions(
userId: Session.PublicData["userId"]
): Promise {
return new Promise((resolve, reject) => {
getAuthRedis()
.lrange(`device:${String(userId)}`, 0, -1)
.then((result) => {
if (result) {
resolve(
result.map((handle) => {
return this.getSession(handle)
})
)
} else {
resolve([])
}
})
.catch(reject)
})
},
updateSession(
handle: string,
session: Partial
): Promise {
return new Promise((resolve, reject) => {
getAuthRedis()
.get(`token:${handle}`)
.then((result) => {
if (result) {
const oldSession = JSON.parse(result) as SessionModel
const merge = Object.assign(oldSession, session)
getAuthRedis()
.set(`token:${handle}`, JSON.stringify(merge))
.catch(reject)
}
reject(new Error("cant update session"))
})
})
},
},
}),
],
})
```
--------------------------------
### Blitz Authentication with Passport.js
Source: https://blitzjs.com/docs/rpc-overview
Guides on integrating Blitz.js authentication with third-party login providers using Passport.js. Covers setup, configuration, session management, server-side APIs, client-side APIs, authorization, and security best practices.
```APIDOC
Blitz Auth with Passport.js:
- Setup and Configuration
- Session Management
- Server-Side APIs
- Client-Side APIs
- Authorization & Security
- Third Party Login
```
--------------------------------
### Setup Blitz Client API
Source: https://blitzjs.com/docs/blitzjs-next
API definition for setupBlitzClient, which takes an array of plugins and returns the withBlitz HOC for client-side integration.
```APIDOC
setupBlitzClient({
plugins: [],
})
#### Arguments
* `plugins:` An array of Blitz.js plugins
* **Required**
#### Returns
An object with the `withBlitz` HOC wrapper
```
--------------------------------
### Setup Blitz Server API
Source: https://blitzjs.com/docs/blitzjs-next
API definition for setupBlitzServer, which accepts plugins and an optional onError callback for server-side integration.
```APIDOC
setupBlitzServer({
plugins: [],
onError?: (err) => void
})
#### Arguments
* `plugins:` An array of Blitz.js plugins
* **Required**
* `onError:` Catch all errors _(Great for services like sentry)_
#### Returns
An object with the `gSSP`, `gSP` & `api` wrappers.
```
--------------------------------
### Check Blitz Version
Source: https://blitzjs.com/docs/tutorial
This command checks if Blitz is installed and displays the installed version. If Blitz is not installed, it will return a 'command not found' error.
```bash
blitz -v
```
--------------------------------
### Blitz Server Setup with Auth
Source: https://blitzjs.com/docs/auth-setup
Configures the Blitz.js server with the AuthServerPlugin, integrating Prisma storage and role-based authorization.
```javascript
import { setupBlitzServer } from "@blitzjs/next"
import {
AuthServerPlugin,
PrismaStorage,
simpleRolesIsAuthorized,
} from "@blitzjs/auth"
import { db } from "db"
import { authConfig } from "./blitz-client"
const { gSSP, gSP, api } = setupBlitzServer({
plugins: [
AuthServerPlugin({
...authConfig,
storage: PrismaStorage(db),
isAuthorized: simpleRolesIsAuthorized,
}),
],
})
export { gSSP, gSP, api }
```
--------------------------------
### Vitest Basic Test Example
Source: https://blitzjs.com/docs/testing
A simple example of a test file using Vitest. It imports a function and asserts its output.
```javascript
import something from "./somewhere"
it("does something", () => {
const result = something()
expect(result).toBe(true)
})
```
--------------------------------
### Configure Blitz.js Server Plugins
Source: https://blitzjs.com/docs/upgrading-from-framework
This TypeScript code snippet demonstrates how to set up the Blitz.js server with authentication and RPC plugins, including database storage configuration.
```typescript
import { setupBlitzServer } from "@blitzjs/next"
import {
AuthServerPlugin,
PrismaStorage,
simpleRolesIsAuthorized,
} from "@blitzjs/auth"
import { db } from "db"
const { gSSP, gSP, api } = setupBlitzServer({
plugins: [
AuthServerPlugin({
cookiePrefix: "blitz-app",
storage: PrismaStorage(db),
isAuthorized: simpleRolesIsAuthorized,
}),
],
})
export { gSSP, gSP, api }
```
--------------------------------
### Blitz CLI Commands Overview
Source: https://blitzjs.com/docs/index
A list of common Blitz CLI commands for managing projects, including creating new apps, running the development server, building for production, managing Prisma, generating code, and more.
```bash
blitz new
blitz dev
blitz start
blitz build
blitz prisma
blitz generate
blitz codegen
blitz routes
blitz console
blitz install
```
--------------------------------
### Blitz Client Setup with Auth Plugin
Source: https://blitzjs.com/docs/blitz-auth-with-next
Configures the Blitz.js client-side setup for a Next.js application, integrating the AuthClientPlugin with a custom cookie prefix.
```typescript
// src/blitz-client.ts:
import { AuthClientPlugin } from "@blitzjs/auth"
import { setupBlitzClient } from "@blitzjs/next"
export const authConfig = {
cookiePrefix: "blitz-auth-with-next-app",
}
export const { withBlitz } = setupBlitzClient({
plugins: [AuthClientPlugin(authConfig)],
})
```
--------------------------------
### Blitz.js Project File Structure Overview
Source: https://blitzjs.com/docs/tutorial
Illustrates the typical directory and file structure generated by `blitz new`. Highlights key directories like `src/`, `db/`, and `public/` and their purposes.
```text
my-blitz-app
├── src/
│ ├── auth/
│ │ ├── components/
│ │ │ ├── LoginForm.tsx
│ │ │ └── SignupForm.tsx
│ │ ├── mutations/
│ │ │ ├── changePassword.ts
│ │ │ ├── forgotPassword.test.ts
│ │ │ ├── forgotPassword.ts
│ │ │ ├── login.ts
│ │ │ ├── logout.ts
│ │ │ ├── resetPassword.test.ts
│ │ │ ├── resetPassword.ts
│ │ │ └── signup.ts
│ │ └── validations.ts
│ ├── core/
│ │ ├── components/
│ │ │ ├── Form.tsx
│ │ │ └── LabeledTextField.tsx
│ │ └── layouts/
│ │ └── Layout.tsx
│ ├── users/
│ │ ├── hooks/
│ │ │ └── useCurrentUser.ts
│ │ └── queries/
│ │ └── getCurrentUser.ts
│ ├── pages/
│ │ ├── api/
│ │ │ └── rpc/
│ │ │ └── [[...blitz]].ts
│ │ ├── auth/
│ │ │ ├── forgot-password.tsx
│ │ │ ├── login.tsx
│ │ │ └── signup.tsx
│ │ ├── _app.tsx
│ │ ├── _document.tsx
│ │ ├── 404.tsx
│ │ └── index.tsx
│ ├── blitz-client.ts
│ └── blitz-server.ts
├── db/
│ ├── migrations/
│ ├── index.ts
│ ├── schema.prisma
│ └── seeds.ts
├── integrations/
├── mailers/
│ └── forgotPasswordMailer.ts
├── public/
│ ├── favicon.ico*
│ └── logo.png
├── test/
│ └── setup.ts
├── README.md
├── next.config.js
├── vitest.config.ts
├── package.json
├── tsconfig.json
├── types.d.ts
├── types.ts
└── yarn.lock
```
--------------------------------
### RPC Call Versioning Example
Source: https://blitzjs.com/docs/rpc-specification
An example illustrating an RPC call that is protected by a user-friendly message mechanism, likely to inform users about version mismatches.
```javascript
// *: example of an RPC call shielded by a friendly message to the user
```
--------------------------------
### Blitz.js Home Page Component Example
Source: https://blitzjs.com/docs/tutorial
Example of a React component for the Blitz.js home page (`pages/index.tsx`). It includes a simple heading and a Suspense boundary for user information.
```typescript
//...\n\nconst Home: BlitzPage = () => {\n return (\n Hello, world!
\n )\n}\n
//...
```