lambert
lambert
Explore posts from servers
BABetter Auth
Created by lambert on 2/19/2025 in #help
Refetching session for additionalFields change
Hey, I added an additionalField to my session called activeProjectId. I didn't find something to update the session from the official API. So per a Discord conversation I update it via my ORM. Now when I call my set-active endpoint I need to update the session to reflect the change. The only way I found was $store.notfiy("$sessionSignal"). This is undocumented and is probably going to change in the future. Do you have an "right" way to update my session after a change to my session? Thanks in advance!
3 replies
BABetter Auth
Created by lambert on 2/11/2025 in #help
Creating declaration files results in too long type
Hi, I'm currently using Hono RPC and want to export my Router as a type for the frontend. The problem I'm facing is that when I'm compiling the declaration files to relieve tsserver of inferring them, it crashes with this error message.
src/lib/auth.ts:18:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

18 export const auth = betterAuth({
~~~~

[11:24:50 PM] Found 1 error. Watching for file changes.
src/lib/auth.ts:18:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

18 export const auth = betterAuth({
~~~~

[11:24:50 PM] Found 1 error. Watching for file changes.
I'm currently using the admin, organization, magicLink, passKey and twoFactor Plugins and a prisma adapter with postgres Is this known, can I fix this somehow? Thanks in advance!
4 replies
HHono
Created by lambert on 2/11/2025 in #help
RPC typing is behaving weird
I'm not sure if this might be an issue with my setup or with Hono itself, but I'm a bit at a loss here I have a Hono router for projects which I want to use as a projectsClient with hc. For this I take my projects Router and extract the Type like this:
type ProjectsRouter = typeof projectRoutes;
// The resulting type is:
type ProjectsRouter = Hono<BlankEnv, {
"/": {
$get: {
input: {};
output: {
projects: {
name: string;
id: string;
image: string | null;
url: string | null;
slug: string;
description: string | null;
}[];
};
outputFormat: "json";
status: 200;
};
};
} & {
...;
}, "/">
type ProjectsRouter = typeof projectRoutes;
// The resulting type is:
type ProjectsRouter = Hono<BlankEnv, {
"/": {
$get: {
input: {};
output: {
projects: {
name: string;
id: string;
image: string | null;
url: string | null;
slug: string;
description: string | null;
}[];
};
outputFormat: "json";
status: 200;
};
};
} & {
...;
}, "/">
Now I import ProjectsRouter in my frontend and my "/" output changes to [x: string]: any;
type ProjectsRouter = Hono<BlankEnv, {
"/": {
$get: {
input: {};
output: {
[x: string]: any;
};
outputFormat: "json";
status: 200;
};
};
} & {
"/": {
$post: {
input: {
json: {
name: string;
slug: string;
image?: string | undefined;
url?: string | undefined;
description?: string | undefined;
};
};
output: {
...;
};
outputFormat: "json";
status: ContentfulStatusCode;
};
};
}, "/">
type ProjectsRouter = Hono<BlankEnv, {
"/": {
$get: {
input: {};
output: {
[x: string]: any;
};
outputFormat: "json";
status: 200;
};
};
} & {
"/": {
$post: {
input: {
json: {
name: string;
slug: string;
image?: string | undefined;
url?: string | undefined;
description?: string | undefined;
};
};
output: {
...;
};
outputFormat: "json";
status: ContentfulStatusCode;
};
};
}, "/">
I thought it might by my Typescript version or any other version but they work fine. Any other type exported from my backend to frontend works too. Anyone might have an idea here? Thanks in advance!
30 replies
TTCTheo's Typesafe Cult
Created by lambert on 5/27/2023 in #questions
Search URL structuring
Hi guys, I have a dynamic URL in Next: search/[word]/[[...rest]] and I was wondering how would I parse this best? I don't want to build the URL out directly, I want to keep it somewhat dynamic so I can do something like this: /search/Hello T3/tags/typescript|next/length/1-10 and structure it any way I like and leave stuff out I don't need. My code currently is this, but I feel like this is super stupid:
// Find Index where tags Param is in URL
const tagsIndex = params.rest.findIndex((r) => r === 'tags');
// Get the next param where the values for it are
const tagsPosition = tagsIndex !== -1 ? tagsIndex + 1 : -1;
// Read out the values
const searchTags = tagsPosition !== -1 ? params.rest[tagsPosition]?.split('%7C') ?? [] : [];

const temporaryTokensIndex = params.rest.findIndex((r) => r === 'temporary');
const temporaryTokensPosition = temporaryTokensIndex !== -1 ? temporaryTokensIndex + 1 : -1;
const temporaryTokens =
temporaryTokensPosition !== -1
? params.rest[temporaryTokensPosition]?.split('-').map((t) => parseInt(t)) ?? [0, 0]
: [0, 0];
// Swap if in X-Y X is greater than Y
if (
temporaryTokens[0] &&
temporaryTokens[1] &&
(temporaryTokens[0] ?? 0 > temporaryTokens[1] ?? 0)
) {
const temp = temporaryTokens[1];
temporaryTokens[1] = temporaryTokens[0];
temporaryTokens[0] = temp;
}

const permanentTokensIndex = params.rest.findIndex((r) => r === 'permanent');
const permanentTokensPosition = permanentTokensIndex !== -1 ? permanentTokensIndex + 1 : -1;
const permanentTokens =
permanentTokensPosition !== -1
? params.rest[permanentTokensPosition]?.split('-').map((t) => parseInt(t)) ?? [0, 0]
: [0, 0];
if (
permanentTokens[0] &&
permanentTokens[1] &&
(permanentTokens[0] ?? 0 > permanentTokens[1] ?? 0)
) {
const temp = permanentTokens[1];
permanentTokens[1] = permanentTokens[0];
permanentTokens[0] = temp;
}
// Find Index where tags Param is in URL
const tagsIndex = params.rest.findIndex((r) => r === 'tags');
// Get the next param where the values for it are
const tagsPosition = tagsIndex !== -1 ? tagsIndex + 1 : -1;
// Read out the values
const searchTags = tagsPosition !== -1 ? params.rest[tagsPosition]?.split('%7C') ?? [] : [];

const temporaryTokensIndex = params.rest.findIndex((r) => r === 'temporary');
const temporaryTokensPosition = temporaryTokensIndex !== -1 ? temporaryTokensIndex + 1 : -1;
const temporaryTokens =
temporaryTokensPosition !== -1
? params.rest[temporaryTokensPosition]?.split('-').map((t) => parseInt(t)) ?? [0, 0]
: [0, 0];
// Swap if in X-Y X is greater than Y
if (
temporaryTokens[0] &&
temporaryTokens[1] &&
(temporaryTokens[0] ?? 0 > temporaryTokens[1] ?? 0)
) {
const temp = temporaryTokens[1];
temporaryTokens[1] = temporaryTokens[0];
temporaryTokens[0] = temp;
}

const permanentTokensIndex = params.rest.findIndex((r) => r === 'permanent');
const permanentTokensPosition = permanentTokensIndex !== -1 ? permanentTokensIndex + 1 : -1;
const permanentTokens =
permanentTokensPosition !== -1
? params.rest[permanentTokensPosition]?.split('-').map((t) => parseInt(t)) ?? [0, 0]
: [0, 0];
if (
permanentTokens[0] &&
permanentTokens[1] &&
(permanentTokens[0] ?? 0 > permanentTokens[1] ?? 0)
) {
const temp = permanentTokens[1];
permanentTokens[1] = permanentTokens[0];
permanentTokens[0] = temp;
}
2 replies
TTCTheo's Typesafe Cult
Created by lambert on 3/14/2023 in #questions
TRPC & ReactQuery: How to check if logged in
Hi Guys, how would you check if the current User is logged in? I tried creating a Query which would return a Boolean, extract it into a Component and then conditionally render the Child or a NavitgateTo Component but that resulted in endless re-renders. I don't have the Code right now but it was just a useQuery which would check for isSuccess and data.loggedIn. Thanks in advance!
3 replies
TTCTheo's Typesafe Cult
Created by lambert on 2/10/2023 in #questions
Turborepo & Prisma Environment Variables
Hi, I'm currently setting up my Monorepo with Turborepo and env-vars are... weird.. with it. The problem I'm currently having is, when I'm doing npx prisma db push in my apps/server Folder, it complains about not finding the env file which Turborepo requires to have in the Root of the Workspace. The current "solution" I have is a .env file in the root and the app, but I don't want to update my .env in two places. Thanks in advance!
2 replies