Skip to content

Instantly share code, notes, and snippets.

@merthanmerter
merthanmerter / auth.ts
Last active May 1, 2025 01:24
auth with jose
import { jwtVerify, SignJWT, type JWTPayload } from "jose";
// your env variables
import { env } from "@server/env";
// your context and cookie utils
import type { Context } from "hono";
import { getCookie, setCookie } from "hono/cookie";
import type { CookieOptions } from "hono/utils/cookie";
@merthanmerter
merthanmerter / sidebar.tsx
Last active April 28, 2025 07:38
shadcn sidebar cookie state
const SIDEBAR_DEFAULT_OPEN = true; /* (add) */
const SIDEBAR_COOKIE_NAME = "_sidebar";
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
// ...
function SidebarProvider({
defaultOpen, /* :true (remove) */
// ...
}
// ...
@merthanmerter
merthanmerter / __root.tsx
Last active October 27, 2024 17:08
tanstack router - stateful loader data params
export type RootContext = {
store: JotaiStore;
};
export const Route = createRootRouteWithContext<RootContext>()({
component: Root,
});
export default function Root() {
return <Outlet />;
@merthanmerter
merthanmerter / usage.ts
Created October 23, 2024 18:09
tanstack router- useAsyncNavigate
/**
* @see https://github.com/tanstack/router/discussions/2567
*/
await navigate({
to: "/",
invalidate: false,
clearCache: {
before: true,
after: true,
@merthanmerter
merthanmerter / nextjs-use-params-with-type-conversion.ts
Last active October 27, 2024 17:43
Next.js use-params-with-type-conversion hook
export const useParamsWithTypeConversion = <
T extends { [key: string]: (v: string | string[]) => number | boolean | string }
>(
conversions: T
) => {
const params = useParams()
const convertedParams = {} as { [K in keyof T]: ReturnType<T[K]> }
for (const [key, conversion] of Object.entries(conversions)) {
@merthanmerter
merthanmerter / actions.ts
Last active April 21, 2025 02:59
Next Safe Actions & React Hook Form - Reusable form component
// actions.ts
export const addUpdateProject = privateActionClient
.metadata({ actionName: 'addUpdateProject', description: 'Add or update a project.' })
.schema(projectsInsertSchema)
.action(
async ({ parsedInput, ctx }) => {
const { id, ...rest } = parsedInput
const [{ insertId }] = await ctx.db
.insert(projects)