From 95f283017dada92920cae95c9bc6c6535674c973 Mon Sep 17 00:00:00 2001 From: m5r Date: Tue, 3 Aug 2021 20:02:01 +0800 Subject: [PATCH] fix blitz.config.ts --- app/customers/queries/get-current-customer.ts | 6 +++--- blitz.config.ts | 21 ++++++++++--------- test/setup.ts | 3 ++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/customers/queries/get-current-customer.ts b/app/customers/queries/get-current-customer.ts index c325bb1..c885bc7 100644 --- a/app/customers/queries/get-current-customer.ts +++ b/app/customers/queries/get-current-customer.ts @@ -1,8 +1,8 @@ -import { Ctx } from "blitz"; +import { resolver } from "blitz"; import db from "../../../db"; -export default async function getCurrentCustomer(_ = null, { session }: Ctx) { +export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => { if (!session.userId) return null; return db.customer.findFirst({ @@ -18,4 +18,4 @@ export default async function getCurrentCustomer(_ = null, { session }: Ctx) { user: true, }, }); -} +}); diff --git a/blitz.config.ts b/blitz.config.ts index 5a0fa38..143cab3 100644 --- a/blitz.config.ts +++ b/blitz.config.ts @@ -2,7 +2,7 @@ import { BlitzConfig, sessionMiddleware, simpleRolesIsAuthorized } from "blitz"; const withPWA = require("next-pwa"); -export const config: BlitzConfig = { +const config: BlitzConfig = { middleware: [ sessionMiddleware({ cookiePrefix: "virtual-phone-blitz", @@ -47,12 +47,13 @@ export const config: BlitzConfig = { */ }; -export default process.env.NODE_ENV === "test" - ? config - : withPWA({ - ...config, - pwa: { - dest: "public", - disable: process.env.NODE_ENV !== "production", - }, - }); +module.exports = + process.env.NODE_ENV === "test" + ? config + : withPWA({ + ...config, + pwa: { + dest: "public", + disable: process.env.NODE_ENV !== "production", + }, + }); diff --git a/test/setup.ts b/test/setup.ts index 8544f57..07eac19 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -1,6 +1,7 @@ import { setConfig } from "blitz"; -import { config } from "../blitz.config"; +// see https://github.com/vercel/next.js/issues/4024 +const config = require("../blitz.config"); setConfig({ serverRuntimeConfig: config.serverRuntimeConfig,