Skip to content

Instantly share code, notes, and snippets.

View xcaeser's full-sized avatar

Caeser xcaeser

  • On my laptop
View GitHub Profile
@xcaeser
xcaeser / redis-auth-adapter.ts
Created May 12, 2025 13:15
Redis Better Auth Adapter
import { createAdapter, type CleanedWhere } from "better-auth/adapters";
import crypto from "crypto";
import type Redis from "ioredis";
export interface RedisAdapterConfig {
redis: Redis;
prefix?: string; // e.g. "ba:"
debugLogs?: boolean;
}
@xcaeser
xcaeser / zig_recap.md
Created December 26, 2024 16:41
Zig Recap

Must know on arrays, slices, pointers

Fixed Arrays and Slices:

  • A fixed array has a predefined size.
  • To modify the content of a fixed array, create a slice ([]T) that acts as a pointer to the array's memory.

Dynamic Arrays:

  • Use std.ArrayList (or similar structures) for dynamically sized arrays.
  • You need to initialize it with an allocator using .init(allocator).
  • Remember to free the memory using .deinit() when done.
@xcaeser
xcaeser / auth.ts
Created September 17, 2024 06:12
Next-auth (AuthJs) v5 assign role to user during signup using cookies
import NextAuth, { DefaultSession } from "next-auth";
import Google from "next-auth/providers/google";
import Credentials from "next-auth/providers/credentials";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/prisma";
import { UserRole } from "@prisma/client";
import { cookies } from "next/headers";
declare module "next-auth" {
interface Session {
@xcaeser
xcaeser / index.ts
Last active April 25, 2024 21:51
Declare proper drizzle index.ts or Fix drizzle "sorry, too many clients already" postgres
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
// Fix for "sorry, too many clients already"
declare global {
// eslint-disable-next-line no-var -- only var works here
// If you're only using 'drizzle(queryClient)' then var db: PostgresJsDatabase | undefined;
var db: PostgresJsDatabase<typeof schema> | undefined;