Skip to content

Instantly share code, notes, and snippets.

@mmikhan
mmikhan / list-users.ts
Last active May 5, 2025 11:10
Infer the output type directly from the Better Auth API function
// Infer the output type directly from the Better Auth API function
type ListUsersOutputType = Awaited<ReturnType<typeof auth.api.listUsers>>;
// Implementation
// Use z.custom for non-Zod types or refine further if needed
.output(z.custom<ListUsersOutputType>())
@mmikhan
mmikhan / page.tsx
Created April 27, 2025 11:05
Manual dehydration on a T3 app through the `useAuthQuery` hook
import { auth } from "@/server/auth";
import { createQueryClient } from "@/trpc/query-client";
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; // Import dehydrate and HydrationBoundary
import { headers } from "next/headers";
import Link from "next/link";
import { cache } from "react";
import StateView from "./state";
// Cache the QueryClient per request in RSC
const getQueryClient = cache(() => createQueryClient());
@mmikhan
mmikhan / page.tsx
Created April 27, 2025 11:01
Manual dehydration through T3 `queryClient.fetchQuery` in a RSC
import { auth } from "@/server/auth";
import { createQueryClient } from "@/trpc/query-client";
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; // Import HydrationBoundary
import { headers } from "next/headers";
import Link from "next/link";
import { cache } from "react";
// Cache the QueryClient per request in RSC
const getQueryClient = cache(() => createQueryClient());
@mmikhan
mmikhan / schema.ts
Created March 12, 2025 18:27
Zod mail configuration schema that takes a default empty value for an email field but also can be an empty string
export const mailConfigurationSchema = z.object({
apiKey: z.string().default(""),
fromEmail: z
.string()
.email()
.optional()
.or(z.literal(""))
.default(""),
toName: z.string().default(""),
toEmail: z
@mmikhan
mmikhan / paypal.ts
Last active February 22, 2025 13:53
PayPal TypeScript SDK oAuth fetch token implementation
import { type User } from "@/server/auth/types";
import { type SelectProduct } from "@/server/db/schema/products-schema";
import {
ApiError,
CheckoutPaymentIntent,
Client,
ClientCredentialsAuthManager,
Environment,
LogLevel,
OrderApplicationContextShippingPreference,
@mmikhan
mmikhan / stripe-plan-upgrade-downgrade-dialog.tsx
Created February 21, 2025 19:29
Stripe plan upgrade downgrade dialog with Hook form implementation
"use client";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
@mmikhan
mmikhan / schema.ts
Created February 17, 2025 19:22
An example of Zod schema together with a React client component to submit an array of object through the input form
export const WEBHOOK_CONFIG_MODES = [
{ value: "auto", label: "Auto" },
{ value: "manual", label: "Manual" },
] as const;
export type WebhookConfigMode = (typeof WEBHOOK_CONFIG_MODES)[number];
export const WEBHOOK_CONFIG_MODE_VALUES = WEBHOOK_CONFIG_MODES.map(
(mode) => mode.value,
) as [string, ...string[]];
@mmikhan
mmikhan / stripe-checkout-session-completed.json
Created February 15, 2025 19:45
Stripe checkout session completed event web hook object
{
"api_version": "2025-01-27.acacia",
"created": 1739648336,
"data": {
"object": {
"adaptive_pricing": null,
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 1000,
"amount_total": 1000,
@mmikhan
mmikhan / auth-social-provider-form.tsx
Created February 13, 2025 20:55
Better Auth social providers with Secret Key component
"use client";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
@mmikhan
mmikhan / uploader.tsx
Created December 28, 2024 14:38
Upload Thing reusable client component
"use client";
import { useState } from "react";
import { generateReactHelpers } from "@uploadthing/react";
import type { OurFileRouter } from "@/app/api/uploadthing/core";
export const { uploadFiles } = generateReactHelpers<OurFileRouter>();
interface FormData {
name: string;