All Blog Posts

How to Create Unique Voucher Codes That Don't Collide

My first problem was how to generate the coupon codes. Initially, I wanted a way to put that functionality in the database. But because I want this working superfast and I don't have the luxury of figuring out all the quirks of getting it to work in the database, I opted for a server function. To generate the codes I'll be using the voucher-code-generator-js library from Voucherify. It's a cool little npm package and it works. I found it on the "How to generate unique coupon codes?" blog post.

Feb 21, 2024·1 min read

Where to Even Start with Logging in My Next.Js Stack

Yeah, so I think now that I run user facing applications, I should put more thought into the logging for my apps. I want to find a solution that allows me to see the various things that happen in my apps and to also catch errors as they happen and not much later or not at all This series of articles by better stack seem like a good place to start Logging | Better Stack CommunityLearn everything you want to know about logging. Go from basics to best practices in no time.Better Stack

Feb 21, 2024·1 min read

Asynchronous JavaScript Headaches

Whenever I'm building something and I come across a scenario where I need to get something from my database I typically use the async await pattern but I've never really understood it. I typically use the async await thing and log my response, then I see some promise thing logged onto my response, then I introduce a try catch block. Sometimes that solves my problems, but today that didn't solve my problem. Typically I wrangle a mix of async functions to get it to work somehow but lord knows tha

Feb 21, 2024·1 min read

Next.js Cache Gotcha

This one is a sneaky one, and caching is becoming synonymous with annoying. But that aside, here's the scenario. I'm working on the gift giving application. The use case is someone purchases a gift and that action triggers: * the generation of a voucher code. * the creation of a transaction object that stores the transaction information in the databases and associates the generated gift code with the transaction before sending the user an email with their gift code. Locally it works just fi

Feb 20, 2024·1 min read

How to Use the Supabase Service Role Secret Key in Next.js Routes

On my website, giftthemanexperience.com, I want users to be able to make purchases without them having a user account. The problem I ran into is that without user accounts, the server needs to be the one writing to the transactions table for the users on Supabase in order to bypass the Row Level Security. My issue was similar to this GitHub issue: Using service role secret key with supabase-js on the server #1284 Because I am using Next.js Route Handlers for my server-side functions, I needed

Oct 24, 2023·1 min read