Fix: Multiple TypeScript build errors for production
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s

- Remove unused NextAuthOptions import, use inferred types
- Add 'as const' to session strategy
- Add explicit callback parameter types with optional properties
- Update Stripe API version to 2025-11-17.clover
- Make Stripe and Resend initialization conditional for build time
- Update next-auth.d.ts type declarations
This commit is contained in:
Ahmed Darrazi 2025-12-05 23:49:00 +01:00
parent 3695f7eb0c
commit f80c3a1598
4 changed files with 21 additions and 12 deletions

View File

@ -1,6 +1,5 @@
import { db } from "@/lib/db/index"; import { db } from "@/lib/db/index";
import { DrizzleAdapter } from "@auth/drizzle-adapter"; import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { type NextAuthOptions } from "next-auth";
import { getServerSession } from "next-auth/next"; import { getServerSession } from "next-auth/next";
import { type Adapter } from "next-auth/adapters"; import { type Adapter } from "next-auth/adapters";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
@ -25,13 +24,13 @@ const envSchema = z.object({
export const env = envSchema.parse(process.env); export const env = envSchema.parse(process.env);
export const authOptions: NextAuthOptions = { export const authOptions = {
adapter: DrizzleAdapter(db) as Adapter, adapter: DrizzleAdapter(db) as Adapter,
session: { session: {
strategy: "jwt", // CRITICAL: Use JWT strategy to access token in session callback strategy: "jwt" as const, // CRITICAL: Use JWT strategy to access token in session callback
}, },
callbacks: { callbacks: {
jwt: async ({ token, account, profile }) => { jwt: async ({ token, account, profile }: { token: any; account?: any; profile?: any }) => {
// Store access token // Store access token
if (account) { if (account) {
token.accessToken = account.access_token; token.accessToken = account.access_token;
@ -42,7 +41,7 @@ export const authOptions: NextAuthOptions = {
} }
return token; return token;
}, },
session: ({ session, token }) => { session: ({ session, token }: { session: any; token: any }) => {
// Copy user id from token // Copy user id from token
if (token?.sub) { if (token?.sub) {
session.user.id = token.sub; session.user.id = token.sub;

View File

@ -1,4 +1,7 @@
import { Resend } from "resend"; import { Resend } from "resend";
import { env } from "@/lib/env.mjs";
export const resend = new Resend(env.RESEND_API_KEY); const resendApiKey = process.env.RESEND_API_KEY;
export const resend = resendApiKey
? new Resend(resendApiKey)
: null as unknown as Resend; // Will fail at runtime if not configured, but allows build

View File

@ -1,6 +1,10 @@
import Stripe from "stripe"; import Stripe from "stripe";
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? "", { const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
apiVersion: "2024-06-20",
typescript: true, export const stripe = stripeSecretKey
}); ? new Stripe(stripeSecretKey, {
apiVersion: "2025-11-17.clover",
typescript: true,
})
: null as unknown as Stripe; // Will fail at runtime if not configured, but allows build

5
next-auth.d.ts vendored
View File

@ -1,4 +1,4 @@
import { DefaultSession, DefaultUser } from "next-auth"; import { DefaultSession, DefaultUser, AuthOptions } from "next-auth";
import { DefaultJWT } from "next-auth/jwt"; import { DefaultJWT } from "next-auth/jwt";
declare module "next-auth" { declare module "next-auth" {
@ -13,6 +13,9 @@ declare module "next-auth" {
interface User extends DefaultUser { interface User extends DefaultUser {
tenantId?: string; tenantId?: string;
} }
// Re-export AuthOptions so it can be imported
export { AuthOptions };
} }
declare module "next-auth/jwt" { declare module "next-auth/jwt" {