Aviv
Aviv
TTCTheo's Typesafe Cult
Created by Aviv on 10/4/2023 in #questions
Is my next-auth options written correctly?
No description
3 replies
TTCTheo's Typesafe Cult
Created by Aviv on 9/29/2023 in #questions
[next-auth + google] can't login on production
[next-auth, next 12, google provider, vercel] Logging-in works in dev, but no in production. When I choose an email on the google widget, it redirects me to the login page. There is no error to be seen, all network requests have 200 status, however there's a session request which returns an empty object! I was able to log my env vars successfully. My URI is in this format: https://my-url-jet.vercel.app/ And my redirect URI is in this format: https://my-url-jet.vercel.app/api/auth/callback/google
2 replies
TTCTheo's Typesafe Cult
Created by Aviv on 8/6/2023 in #questions
Importing Prisma
In a file I created, I have the following code. Initially, I imported "prisma" everywhere I needed it. However, I discovered that this approach creates a global variable, allowing me to use "prisma" in other files without importing it explicitly. I'm unsure if this is acceptable or if I should continue importing it to avoid potential issues with using the same instance or other concerns (using next 12)
import { PrismaClient } from '@prisma/client';

let prisma;

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}

prisma = global.prisma;
}

export default prisma;
import { PrismaClient } from '@prisma/client';

let prisma;

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}

prisma = global.prisma;
}

export default prisma;
3 replies
TTCTheo's Typesafe Cult
Created by Aviv on 7/30/2023 in #questions
Nodemailer Error: read ECONNRESET
Hi, i'm using a library called 'react email' with next 12, nodemailer and an outlook email. I try to send a simple email, but get this error: "Something went wrong :/ Error: read ECONNRESET". This is my code (all sensitive info is hidden):
import { render } from '@react-email/render';
import nodemailer from 'nodemailer';
import Email from './templates/test';

export default async function sendEmail() {
const transporter = nodemailer.createTransport({
host: 'smtp-mail.outlook.com',
port: 587,
secure: true,
auth: {
user: '...@outlook.com',
pass: '...',
},
});

const emailHtml = render(<Email />);

const options = {
from: '...@outlook.com',
to: '.@outlook.com',
subject: 'hello world',
html: emailHtml,
};

await transporter.sendMail(options);
}
import { render } from '@react-email/render';
import nodemailer from 'nodemailer';
import Email from './templates/test';

export default async function sendEmail() {
const transporter = nodemailer.createTransport({
host: 'smtp-mail.outlook.com',
port: 587,
secure: true,
auth: {
user: '...@outlook.com',
pass: '...',
},
});

const emailHtml = render(<Email />);

const options = {
from: '...@outlook.com',
to: '.@outlook.com',
subject: 'hello world',
html: emailHtml,
};

await transporter.sendMail(options);
}
2 replies
TTCTheo's Typesafe Cult
Created by Aviv on 6/29/2023 in #questions
Preact Error on next 12
On next 12, I tried to switch to Preact, using the following guide: https://reacthustle.com/blog/how-to-speed-up-your-nextjs-app-with-preact But I get this error: Cannot read properties of undefined (reading '__H') The error seems to refer to a mix of CJS with ESM bundles, but I tried to fix it as specified in this guide, and it didn't work. How my package.json looks: "next-plugin-preact": "^3.0.7", "preact": "^10.15.1", "preact-render-to-string": "^6.1.0", "react": "npm:@preact/compat@^17.1.2", "react-dom": "npm:@preact/compat@^17.1.2",
2 replies
TTCTheo's Typesafe Cult
Created by Aviv on 6/26/2023 in #questions
vscode logging level
I've been asked by Sentry support to do this: "--log-level=debug", because I have an error of: "project not found" whenever i run "npm run build" . What I know is going to vscode settings and configuring some logs to debug mode. Is that what I suppose to do? Thanks!
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 6/8/2023 in #questions
Session recording tools?
Hey! I want to monitor my next app, and before I look for a logging and tracking solution, I want a session recording tool. There are known tools like logrocket and sentry, or lesser known like vwo and inspectlet, which offer 2500-5000 sessions on the free tier. But there's also a completely free tool by microsoft called clarity. Do you have any input on the matter? Thanks!
2 replies
TTCTheo's Typesafe Cult
Created by Aviv on 4/16/2023 in #questions
[next 12] Stripe webhook doesn't work
8 replies
TTCTheo's Typesafe Cult
Created by Aviv on 3/23/2023 in #questions
Is my Stripe code correct?
Hi, I want to offer my users a fixed-term subscription plan, where they get 30 days for free, and then they pay monthly for 12 months. Am I doing this the correct way? (I am not using a webhook since it gives me errors and I have up) Creating a session
const paymentSession = await stripe.checkout.sessions.create({
customer: paymentId,
mode: 'subscription',
payment_method_types: ['card'],
line_items: lineItems,
subscription_data: {
trial_period_days: 30,
},
success_url: `...`,
cancel_url: `...`,
});
const paymentSession = await stripe.checkout.sessions.create({
customer: paymentId,
mode: 'subscription',
payment_method_types: ['card'],
line_items: lineItems,
subscription_data: {
trial_period_days: 30,
},
success_url: `...`,
cancel_url: `...`,
});
Create subscription after the user went through the Stripe widget:
const subscription = await stripe.subscriptionSchedules.create({
customer: customer.id,
start_date: 'now',
end_behavior: 'release',
phases: [
{
items: [
{ price: process.env[`PRICE_${type.toUpperCase()}`], quantity: 1 },
],
iterations: 12,
},
],
});
const subscription = await stripe.subscriptionSchedules.create({
customer: customer.id,
start_date: 'now',
end_behavior: 'release',
phases: [
{
items: [
{ price: process.env[`PRICE_${type.toUpperCase()}`], quantity: 1 },
],
iterations: 12,
},
],
});
7 replies
TTCTheo's Typesafe Cult
Created by Aviv on 3/19/2023 in #questions
Stripe webhook error
Next 12: I've followed Next official guide for integrating stripe into my published site on vercel, and was able to make a purchase, but I fail using a webhook after a successful payment. On the Stripe dashboard, I see this error: "Webhook Error: No signatures found matching the expected signature for payload." My code for my api endpoint for that webhook is taken from the guide: https://github.com/vercel/next.js/blob/canary/examples/with-stripe-typescript/pages/api/webhooks/index.ts
4 replies
TTCTheo's Typesafe Cult
Created by Aviv on 3/12/2023 in #questions
Including multiple tables on prisma
Is there a way to include more than 1 relation in a prisma query? When I write:
include: {
foo: true,
},
include: {
foo: true,
},
It works, but it fails if I add another:
include: {
foo: true,
bar: true
},
include: {
foo: true,
bar: true
},
4 replies
TTCTheo's Typesafe Cult
Created by Aviv on 2/26/2023 in #questions
Tailwind breaks on hot-reload
Tech: Tailwind latest version, next.js 12 I realized that my tailwind breaks (aka some classes suddenly have no effect) on hot-reload, and specifically when I shut down my local server, and run it up again. When I have my localhost opened on the browser, and I re-run the server, the browser performs a re-render, and then the page is rendered broken. I can fix it temporarily but making a change in the broken component, but the problem reappears when I re-run the server. It also is not fixed on pc restart or anything else Seems like i'm not the only one: https://stackoverflow.com/questions/67837075/tailwind-classes-not-working-after-page-refresh-in-production Have any thoughts?
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 2/21/2023 in #questions
Some Tailwind classes have no affect
56 replies
TTCTheo's Typesafe Cult
Created by Aviv on 2/1/2023 in #questions
TinyMCE in react - generates wrong style syntax
I want to use TinyMCE text editor in react, but the text it generates uses style tags on the generated elements, that is written for html and not JSX. Anyone experienced with it?
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 1/9/2023 in #questions
Prisma & CockroachDB - push to array
next 12, prisma 4.7.1, CockroachDB When I try to push an item to an array field, I get an error: "Did you mean set?":
await prisma.character.update({
where: {
id: connectionId,
},
data: {
[connectionField]: {
push: characterId,
},
},
});
await prisma.character.update({
where: {
id: connectionId,
},
data: {
[connectionField]: {
push: characterId,
},
},
});
But it works like this:
const character = await prisma.character.findUnique({
where: {
id: connectionId,
},
});

if (character) {
character[connectionField].push(characterId);

const updatedCharacter = await prisma.character.update({
where: {
id: connectionId,
},
data: {
[connectionField]: character[connectionField],
},
});
return updatedCharacter;
}
const character = await prisma.character.findUnique({
where: {
id: connectionId,
},
});

if (character) {
character[connectionField].push(characterId);

const updatedCharacter = await prisma.character.update({
where: {
id: connectionId,
},
data: {
[connectionField]: character[connectionField],
},
});
return updatedCharacter;
}
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 1/3/2023 in #questions
Prisma find is acting very weird
I have a user table with a relation field of posts. When I try to use "findFirst" for a user by id, and get the posts using "include: true", I get returned a user with an empty posts array. The array shouldn't be empty. I tried "findMany", and what happens is that it returns ALL USERS in the db, which shouldn't happen, cause there's only 1 user who has this unique id, but the users ARE coming back with a none-empty posts array. WTF? const getUser = async (id) => { const user = await prisma.user.findFirst({ where: { id, }, include: { posts: true, }, }); return user; };
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 1/1/2023 in #questions
Prisma many-to-many self-relation
I want to have multiple m2m self-relation fields. For a user I need fields for parents, friends, partners, etc, and all of them are users as well. Prisma let me have 2 fields like this, but generates weird syntax if I do more than 2. Anyone experienced with this?
1 replies
TTCTheo's Typesafe Cult
Created by Aviv on 12/25/2022 in #questions
input type file is cleaned upon tab change
2 replies
TTCTheo's Typesafe Cult
Created by Aviv on 12/22/2022 in #questions
Save me from git
18 replies
TTCTheo's Typesafe Cult
Created by Aviv on 12/21/2022 in #questions
Prisma - creating row with empty array fields
Hi, I have a user table in which I have a reference field of the Story table, written like this: story Story[] When I create a new user, since this field cannot be optional in prisma, I write it like this: return await prisma.story.create({ data: { ... story: [], }, }); I get this error: got invalid value [] on prisma.createOneStory. Provided List<>
9 replies