Debaucus
Debaucus
Explore posts from servers
CDCloudflare Developers
Created by Debaucus on 2/16/2024 in #pages-help
522 Error - Custom domain and www. won't redirect.
No description
3 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 1/1/2024 in #questions
Handling large translation files. Load only when building an option?
I have a 2.2mb translation file, per language. I have quickly noticed using next-i18next loads the whole file, of every translation, on every pageload. I am using getStaticProps with ISR, so I believed I would generate all the pages with the languages intergrated into it, then only send the required needed data for that page (it being pre-translated now). Is there a solution to this? I've tried Google/ChatGPT but I don't know how to word it in a way that gets me to an answer.
2 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 8/19/2023 in #questions
Database Table Design/Layout for Analytics type data?
I am looking to store views and clicks, with the possibility of other types of data moving into the future. I understand a rough idea, but can't quiet comprehend the best way to layout this data. There are lots of ways to do it, but whats the right way? Googling hasn't helped me find much of any use. I could: - Create a column labelled 1-365, then store the data for that day, keep a year per user While this makes sense in my head, and would work, this doesn't scale long term if I want more than one year of data, and would also take a lot of space on day 1 of a new user with 364 0's for the sake of it. I would also need to store a start date, then calculate any functions from that start date, also seems off. I'm not asking for a 'explain everything' answer, but guidance to internet resources where I could learn how this SHOULD be done, rather then whatever works. Thanks!
2 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 7/30/2023 in #questions
Looking for NextAuth Discord Refresh token rotation examples. All mine have expired.
I have created a project that uses Discord as a provider. My refresh_token and access_token's have expired, I've noticed when sign in is performed, it doesn't automatically refresh these details and thus access to oauth with Discord has dropped. I am looking for an implementation that updates these details on signIn. I've found the Google example on the NextAuth (https://authjs.dev/guides/basics/refresh-token-rotation) guide but as it only includes Google and I'm not the brightest, I am looking to do Discord but do it correctly, as login is not something to mess up! Thanks anyone who can help me out 😄
8 replies
TtRPC
Created by Debaucus on 7/4/2023 in #❓-help
TRPC -useInfiniteQuery() refreshes all data when an input is varied, how to use?
So I have a TRPC infiniteQuery:
const { data, fetchNextPage, hasNextPage } =
trpc.server.getAll.useInfiniteQuery(
{
limit: 3,
tag: page,
},
{
getNextPageParam: (lastPage) =>
lastPage[lastPage.length - 1]?.nextCursor ?? null,
}
);
const { data, fetchNextPage, hasNextPage } =
trpc.server.getAll.useInfiniteQuery(
{
limit: 3,
tag: page,
},
{
getNextPageParam: (lastPage) =>
lastPage[lastPage.length - 1]?.nextCursor ?? null,
}
);
As an example, for each 3 gathered, I increase the value of page by 1, when page = 2, the page does a query, resets the pages content and triggers a repeating loop of queries. I want to pass a varying value, be it string or number, to the query and be able to continue from the old content. Any help is welcome
16 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 7/4/2023 in #questions
TRPC -useInfiniteQuery() refreshes all data when an input is varied, how to use?
So I have a TRPC infiniteQuery:
const { data, fetchNextPage, hasNextPage } =
trpc.server.getAll.useInfiniteQuery(
{
limit: 3,
tag: page,
},
{
getNextPageParam: (lastPage) =>
lastPage[lastPage.length - 1]?.nextCursor ?? null,
}
);
const { data, fetchNextPage, hasNextPage } =
trpc.server.getAll.useInfiniteQuery(
{
limit: 3,
tag: page,
},
{
getNextPageParam: (lastPage) =>
lastPage[lastPage.length - 1]?.nextCursor ?? null,
}
);
As an example, for each 3 gathered, I increase the value of page by 1, when page = 2, the page does a query, resets the pages content and triggers a repeating loop of queries. I want to pass a varying value, be it string or number, to the query and be able to continue from the old content. Any help is welcome
3 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 6/28/2023 in #questions
Force page data fetch with TRPC? Edit form cacheing older data.
I have an edit form. If a user creates edits, submits, then immediately returns to the page the data is cached and displays the old information. What is the correct policy for handling this issue?
6 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 6/21/2023 in #questions
Planetscale - New field with default(uuid) erroring out?
model Server {
***
apikey String @unique @default(uuid())
***
}
model Server {
***
apikey String @unique @default(uuid())
***
}
This is a new addition to my database, I can't seem to sync my planetscale database with this as it errors out, I also tried with @unique removed and with cuid(). Field 'apikey' doesn't have a default value (errno 1364) (sqlstate HY000) during query: insert into Server Googling error with 'planetscale' doesn't help. Thier help support has nothing either.. HELP!
5 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 6/16/2023 in #questions
With Planetscale (or others), what's the correct way to retroactively edit a prod database?
Noob question I don't know how to Google correctly. Let's say I forgot to add a username field to the users portion of my database. In Planetscale, you can't push a development branch to production without a default value if the field can't be null, for example. Or, let's say I didn't have 'creation date' in one table, but now I need it and want to import it over. I find it hard to wrap my head around how to do this correctly. Any advice (or guides on YouTube or text) would be very helpful! Thanks 👍
5 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 5/31/2023 in #questions
Change ctx.session.user values to include new ones? Bad idea?
Right now when using ctx.session.user I get a few default options that come with t3-app. .id, .name?, .image? and .email?. Is there a way to change this to include new values? I can't find an obvious spot or I am being silly.
5 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 4/4/2023 in #questions
@unqiue in Prisma Schema. With mySQL/Planetscale, does case sensitivity matter?
Lets take a standard
model User {
name String @unique
}
model User {
name String @unique
}
I understand from reading up (I think at least) that mySQL doesn't care for case sensitivity when using a select query. But what about when inserting data? Does Debaucus match the same way that debaucus does? Because that would lead to issues with usernames and being unique. If that is correct, the unique doesn't cover this edge case, how do you rectify this issue?
4 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 4/2/2023 in #questions
tRPC prefetching URL slower? - What am I doing wrong here.
I've been toying with ISR attempts, failing, so moved back and am going step by step. During testing, I tried (and by the loading page details of the JSON) succeeded! The pre-fetched data is there! However, the page is 30% slower in lighthouse! Am I doing this wrong? The goal is to eventually have it cached for SEO purposes, so pre-fetch of just the query isn't quiet there yet.
import Head from "next/head";
import { trpc } from "../utils/trpc";
import ListPageSingle from "./components/listPageSingle";

import { createProxySSGHelpers } from "@trpc/react-query/ssg";
import { appRouter } from "../server/trpc/router/_app";
import superjson from "superjson";
import { PrismaClient } from "@prisma/client";
import { InferGetServerSidePropsType } from "next";

const prisma = new PrismaClient();

export async function getStaticProps() {
const ssg = createProxySSGHelpers({
router: appRouter,
ctx: { session: null, prisma },
transformer: superjson,
});

await ssg.post.getpostTypes.prefetch("discord");

return {
props: {
trpcState: ssg.dehydrate(),
},
};
}

export default function DiscordPage(
props: InferGetServerSidePropsType<typeof getStaticProps>
) {
const { data: postQuery = [] } =
trpc.post.getpostTypes.useQuery("discord");

return (
<>
<Head>
<title>title</title>
</Head>
<h1 className="text-5xl">header</h1>
<p>
paragraph
</p>
<p>{JSON.stringify(postQuery)}</p>
<div className="my-10 h-0 w-auto border border-gray-200"></div>
<ListPageSingle queryData={postQuery} />
</>
);
}
import Head from "next/head";
import { trpc } from "../utils/trpc";
import ListPageSingle from "./components/listPageSingle";

import { createProxySSGHelpers } from "@trpc/react-query/ssg";
import { appRouter } from "../server/trpc/router/_app";
import superjson from "superjson";
import { PrismaClient } from "@prisma/client";
import { InferGetServerSidePropsType } from "next";

const prisma = new PrismaClient();

export async function getStaticProps() {
const ssg = createProxySSGHelpers({
router: appRouter,
ctx: { session: null, prisma },
transformer: superjson,
});

await ssg.post.getpostTypes.prefetch("discord");

return {
props: {
trpcState: ssg.dehydrate(),
},
};
}

export default function DiscordPage(
props: InferGetServerSidePropsType<typeof getStaticProps>
) {
const { data: postQuery = [] } =
trpc.post.getpostTypes.useQuery("discord");

return (
<>
<Head>
<title>title</title>
</Head>
<h1 className="text-5xl">header</h1>
<p>
paragraph
</p>
<p>{JSON.stringify(postQuery)}</p>
<div className="my-10 h-0 w-auto border border-gray-200"></div>
<ListPageSingle queryData={postQuery} />
</>
);
}
17 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/31/2023 in #questions
tRPC query 'train'. what's the correct method to grab data from multiple sources?
I'm going to make an example as I'm either struggling to understand or am building my database wrong. A user has a profile page, to load this profile page we use the URL value. So I query tRPC when the username is entered into the URL /profile/Debaucus I now get back the details for Debaucus, it's a real page. Next, I want to query all the users posts, stored in a separate table, called posts. If I make a new tRPC query, I get the 'too many re-renders' as I am doing multiple chains, as I am using the ID recovered from the first query in the second Load page > use slug for tRPC query to get data > use that data to tRPC query more data? Is this incorrect methodology?
13 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/23/2023 in #questions
Scalar lists but on Planetscale?
After starting to watch the tutorial posted day, I bit the bullet and am going to give planetscale a try! I use 2 scalar lists in my current setup to store an array of tags for posts. These don't work on planetscale. Database experts (or simply not a noob like me!) What is the best alternative to use?
model Example {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
post String
postTags String[]
}
model Example {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
post String
postTags String[]
}
Field "postTags" in model "Example" can't be a list. The current connector does not support lists of primitive types.
Field "postTags" in model "Example" can't be a list. The current connector does not support lists of primitive types.
1 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/18/2023 in #questions
.upsert when no way to track query/track unique identifier?
I have a (plan to) setup where a user can like multiple posts. This can be done once per day.
model UserLikeStreaks {
id String @id @default(cuid())
serverID String
userID String
likeCount Int
likeTotal Int
createdAt DateTime @default(now())
recentLike DateTime @updatedAt
}
model UserLikeStreaks {
id String @id @default(cuid())
serverID String
userID String
likeCount Int
likeTotal Int
createdAt DateTime @default(now())
recentLike DateTime @updatedAt
}
Here is my structure, my logic being that I can query the where: { serverID, userID} and get the results of previous. Here's where I am misunderstanding, upsert only allows for one where entry? But I would need to query both in order to verify the correct entry.
ctx.prisma.userLikeStreaks.upsert({
where: {
serverID: input.server_id,
userID: ctx.session.id,

},
update: {
likeCount: {
increment: 1,
},
likeTotal: {
increment: 1,
},
},
create: {
serverID: input.server_id,
userID: ctx.session.id,
likeCount: 1,
likeTotal: 1,
},
}),
ctx.prisma.userLikeStreaks.upsert({
where: {
serverID: input.server_id,
userID: ctx.session.id,

},
update: {
likeCount: {
increment: 1,
},
likeTotal: {
increment: 1,
},
},
create: {
serverID: input.server_id,
userID: ctx.session.id,
likeCount: 1,
likeTotal: 1,
},
}),
This is the error I get inside VSCode:
Type '{ serverID: string; userID: string; }' is not assignable to type 'UserLikeStreaksWhereUniqueInput'.
Object literal may only specify known properties, and 'serverID' does not exist in type 'UserLikeStreaksWhereUniqueInput'.ts(2322)
Type '{ serverID: string; userID: string; }' is not assignable to type 'UserLikeStreaksWhereUniqueInput'.
Object literal may only specify known properties, and 'serverID' does not exist in type 'UserLikeStreaksWhereUniqueInput'.ts(2322)
5 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/15/2023 in #questions
Prisma Docs not working as instructed for insensitive case search. 9am and my brain hurts.
const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
has: input,
},
},
orderBy: {
votes: "desc",
},
});
const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
has: input,
},
},
orderBy: {
votes: "desc",
},
});
I am using the input of a URL to then query my database, so for example Discord. This works correctly, however it doesn't work for lower case, such as discord. Looking at the Prisma docs (https://www.prisma.io/docs/concepts/components/prisma-client/case-sensitivity) it instructs me to to use mode: 'insensitive',. This does not work and the TypeScript error is as follows when placing the code under has: input,
Type '{ has: string; mode: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'mode' does not exist in type 'StringNullableListFilter'.ts(2322)
Type '{ has: string; mode: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'mode' does not exist in type 'StringNullableListFilter'.ts(2322)
I believe this is telling me because I don't have a mode in the database, it can't be used. Which makes sense? But then what is the correct way to filter case insensitive?
18 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/11/2023 in #questions
[Noob] Not understanding how to create an edit form.
I have 2 major questions/problems, full noob to thank you for any guidance. I am trying to create an edit form for already submitted data, profile related data like username, description etc. During this process, a user picks a URL choice.
defaultValues: {
title: "",
slug: "",
name: "",
serverType: "",
authorId: sessionData?.user?.id,
content: "",
shortDescription: "",
votes: 0,
published: true,
},
defaultValues: {
title: "",
slug: "",
name: "",
serverType: "",
authorId: sessionData?.user?.id,
content: "",
shortDescription: "",
votes: 0,
published: true,
},
The edit form is using the same base, with some removed. This includes slug being removed.
defaultValues: {
title: "",
name: "",
serverType: "",
authorId: sessionData?.user?.id,
content: "",
shortDescription: "",
published: true,
},
defaultValues: {
title: "",
name: "",
serverType: "",
authorId: sessionData?.user?.id,
content: "",
shortDescription: "",
published: true,
},
This is where my questions begin: 1) Because Slug is required, I was getting issues where the default value being loaded in doesn't really work. I am struggling to understand how I load in the data for an edit form to then be re-submitted. Any examples of correct ways to load in data on a page to then be re-submitted? 2) When submiting data during testing, I would get errors related to slug not being included, or already being added. I am using mutate inside trpc so I am again feeling like I am missing some understanding. Thank you!
23 replies
CDCloudflare Developers
Created by Debaucus on 1/29/2023 in #pages-help
Google Webmasters Authentication Nuked my settings. Help!
I setup Cloudflare pages and everything was working correctly with a custom domain. I added my website to Google Webmasters which updates once of my cname records, in doing so it has stopped my website being able to be resolved. What are my records supposed to look like so I can fix this?
10 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 1/10/2023 in #questions
TRPC Server Side verification of action.
I have a button that can only be pressed once a day (as a vote). I've made it so the button turns to disabled when a vote has already been processed, or a click for the day. I've read previously never trust the client, so are there any additional steps/best practices I should take in order to stop abuse? My mind leads towards doing a check query whenever a button press is handled, but unsure.
vote: protectedProcedure
.input(
z.object({
server_id: z.string(),
})
)
.mutation(({ ctx, input }) => {
// Promise all means it perfroms both actions. Previously only the .update happened.
return Promise.all([
ctx.prisma.votes.create({
data: {
server_id: input.server_id,
user_id: ctx.session.id,
},
}),
ctx.prisma.server.update({
where: {
id: input.server_id,
},
data: {
votes: {
increment: 1,
},
},
}),
]);
}),
vote: protectedProcedure
.input(
z.object({
server_id: z.string(),
})
)
.mutation(({ ctx, input }) => {
// Promise all means it perfroms both actions. Previously only the .update happened.
return Promise.all([
ctx.prisma.votes.create({
data: {
server_id: input.server_id,
user_id: ctx.session.id,
},
}),
ctx.prisma.server.update({
where: {
id: input.server_id,
},
data: {
votes: {
increment: 1,
},
},
}),
]);
}),
5 replies