Skip to main content

Posts

Showing posts from November, 2024

How to Make a Public NPM Package of NestJS Mongoose Schema

Building microservices often requires sharing database schemas across projects. As a NestJS developer, I struggled to figure out the best way to create a reusable package for my Mongoose schemas. After some trial and error, I finally cracked the process. Here’s a step-by-step guide to help you do the same. Step 1: Create an NPM Account Before you begin, ensure you have an NPM account. Public packages are free, while private ones require a subscription. For this tutorial, we’ll use a public package. Step 2: Initialize Your Package Open your terminal and run: mkdir package-name cd package-name npm init Follow the prompts to set up your package. You need to add a unique name to publish your package. Step 3: Install Dependencies Run the following commands to install the required dependencies: npm install @nestjs/common rxjs reflect-metadata npm install -D @types/node rimraf typescript Step 4: Update package.json Edit your package.json to look like this: { "main" : "dis...

๐Ÿ” Protecting Your Next.js App: Redirecting Unauthorized Users to the Login Page with Middleware

Introduction When building an app with Next.js, ensuring that only authenticated users access certain pages is crucial for protecting sensitive data. One effective way to do this is by implementing a global authentication check with middleware. This approach lets you automatically redirect unauthorized users to the login page without needing to repeat checks across multiple pages. In this article, I’ll walk you through setting up a global authentication check using Next.js middleware and share some useful client-side tricks for extra protection. Why Use Middleware for Authentication in Next.js? Next.js middleware is a powerful tool that can intercept and process requests before they reach the route handlers. By implementing middleware, you can: Centralize Authentication Logic: No need to handle authentication on each page. Protect Multiple Pages Efficiently: Easily redirect unauthorized users across many routes. Improve Code Readability and Maintenance: Keeping authentication in on...

Title: ❌ Solving the “Codegen did not run properly” Error in React Native Projects

  If you’ve been working with React Native, you may have encountered the frustrating error: error: Codegen did not run properly in your project. Please reinstall cocoapods with bundle exec pod install. This error can pop up unexpectedly, especially after clearing caches or updating dependencies. In this post, I’ll walk you through the steps I took to resolve this issue. How I Encountered the Problem After cleaning up my project cache, I ran into this error when trying to build my iOS project. The suggestion was straightforward: run bundle exec pod install . So I followed the instructions and ran: bundle exec pod install But instead of solving the problem, I got another error: Could not locate Gemfile or .bundle/ directory This was a bit confusing. Normally, bundle exec pod install works well if you have a Gemfile set up to manage CocoaPods. But in my case, there was no Gemfile, and this error left me searching for answers. Solution: Installing CocoaPods Directly After t...

Can’t Change Default Permission String in Expo? Here’s How I Solved It!

Submitting an app to the App Store can be a nerve-wracking experience, especially when Apple rejects your app for unclear or default permission strings. This is a common issue for developers using Expo, particularly with modules like expo-location . Apple requires a clear, customized description for each permission your app requests, and the default permission strings provided by Expo often fall short of their guidelines. I recently faced this challenge while trying to submit an Expo app to the App Store, and the road to solving it wasn’t straightforward. After trying multiple approaches and running into dead ends, I finally found a solution that worked. Here’s everything you need to know about resolving this issue, based on my experience. The Problem Apple’s App Store review process requires apps to provide clear, custom messages explaining why permissions, such as location access, are being requested. If your app uses the expo-location module, Expo provides default permission string...

How to Build an Android App with Expo Using eas build --local

  Developing and deploying an Android app with Expo’s EAS (Expo Application Services) has simplified many aspects of mobile app development. Here’s a step-by-step guide to building an Android app bundle using eas build --local , signing it with a custom keystore, and deploying it to Google Play. Step 1: Open Your App in Android Studio Launch Android Studio . Open your Expo project’s Android directory (e.g., my-todo/android ). Go to Build > Generate Signed Bundle / APK… If this option is grayed out, first click Build Bundle(s) / APK(s) to trigger an initial build. Then the option will become available. Step 2: Generate a Keystore In the Generate Signed Bundle / APK dialog, select Android App Bundle and click Next . Under Key store path , choose Create new… . Complete all required fields for the new keystore form (including passwords and alias). Click OK to save the keystore, then Next to proceed. Note the location of the generated keystore file. Step 3: Configure ...