conniehunt
conniehunt
Explore posts from servers
TTCTheo's Typesafe Cult
Created by conniehunt on 9/8/2023 in #questions
T3env: Module not found: Can't resolve '@/env.mjs'
Hi, I am trying to use T3env for the first time but i keep getting this error in build Module not found: Can't resolve '@/env.mjs'. My env.mjs is in my src folder. here is my env.mjs file:
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
OPEN_AI_API_KEY: z.string().min(1),
OPEN_AI_ORGANIZATION_ID: z.string().min(1),
BITLY_ACCESS_TOKEN: z.string().min(1),
PASSWORD: z.string().min(1),
CLERK_SECRET_KEY: z.string().min(1),
WEBHOOK_SECRET: z.string().min(1),
RESEND_API_KEY: z.string().min(1),
},
client: {
NEXT_PUBLIC_LOCAL_URL: z.string().url(),
NEXT_PUBLIC_VERCEL_URL: z.string().url(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
experimental__runtimeEnv: {
NEXT_PUBLIC_LOCAL_URL: process.env.NEXT_PUBLIC_LOCAL_URL,
NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_VERCEL_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
},
});
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
OPEN_AI_API_KEY: z.string().min(1),
OPEN_AI_ORGANIZATION_ID: z.string().min(1),
BITLY_ACCESS_TOKEN: z.string().min(1),
PASSWORD: z.string().min(1),
CLERK_SECRET_KEY: z.string().min(1),
WEBHOOK_SECRET: z.string().min(1),
RESEND_API_KEY: z.string().min(1),
},
client: {
NEXT_PUBLIC_LOCAL_URL: z.string().url(),
NEXT_PUBLIC_VERCEL_URL: z.string().url(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
experimental__runtimeEnv: {
NEXT_PUBLIC_LOCAL_URL: process.env.NEXT_PUBLIC_LOCAL_URL,
NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_VERCEL_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
},
});
Very confused, since ive followed the documentation exactly aside from including import "./src/env.mjs"; in my next.config.js since I can't use imports outside of a module
2 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
10 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/21/2023 in #questions
API route call from another API route
hoping someone can help me here. Below is my NextJs(v13 app dir) Api route which Stripe forwards webhooks to, when the event.type of "checkout.session.completed" is sent i want to call another API route (add-credits).
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

export async function POST(req: any) {
const rawBody = await buffer(req.body);
let event;
try {
event = stripe.webhooks.constructEvent(
rawBody,
req.headers.get('stripe-signature') as string,
process.env.STRIPE_WEBHOOK_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

export async function POST(req: any) {
const rawBody = await buffer(req.body);
let event;
try {
event = stripe.webhooks.constructEvent(
rawBody,
req.headers.get('stripe-signature') as string,
process.env.STRIPE_WEBHOOK_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
When the call to add-credits route is made i get status code 200 but it says (MISS) in console
2 replies