MadMax
MadMax
Explore posts from servers
TtRPC
Created by MadMax on 4/1/2024 in #❓-help
Tried to access "$types.prototype" which is not available at runtime
No description
8 replies
TtRPC
Created by MadMax on 1/21/2024 in #❓-help
How to infer query types on client?
export const tenantRouter = router({
getTenants: procedure.query(() => {
return { hello: "world" };
}),
getTenant: procedure.query(async ({ ctx }) => {
const res = await getTenantById(ctx.user.tenant_id);
if (res.isError() || !res.value) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Tenant not found",
});
}
return res.value;
}),
});
export const tenantRouter = router({
getTenants: procedure.query(() => {
return { hello: "world" };
}),
getTenant: procedure.query(async ({ ctx }) => {
const res = await getTenantById(ctx.user.tenant_id);
if (res.isError() || !res.value) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Tenant not found",
});
}
return res.value;
}),
});
client code
export const GetTest = () => {
const test = trpc.getTenants.useQuery();
const test2 = trpc.getTenant.useQuery();
console.log(test2.data);
return (
<>
{/* <h1>{test2.data?.hello}</h1> */}
<pre>{test.data?.hello}</pre>
</>
);
};
export const GetTest = () => {
const test = trpc.getTenants.useQuery();
const test2 = trpc.getTenant.useQuery();
console.log(test2.data);
return (
<>
{/* <h1>{test2.data?.hello}</h1> */}
<pre>{test.data?.hello}</pre>
</>
);
};
6 replies
TTCTheo's Typesafe Cult
Created by MadMax on 11/27/2023 in #questions
Getting role undefined in session even though it exist in db
interface UserRole {
role: "pleb" | "admin";
}

declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
role: UserRole;
} & DefaultSession["user"];
}

interface User {
// ...other properties
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
},
}),
},
//@ts-ignored
adapter: DrizzleAdapter(db, mysqlTable),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
interface UserRole {
role: "pleb" | "admin";
}

declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
role: UserRole;
} & DefaultSession["user"];
}

interface User {
// ...other properties
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
},
}),
},
//@ts-ignored
adapter: DrizzleAdapter(db, mysqlTable),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
7 replies