Authentication with Hono - JWT, Bun, TypeScript, REST API
Nick Olson Codes
View ChannelAbout
Learn full stack web development with TypeScript, Bun, Hono, Postgres, and React
Latest Posts
Video Description
GitHub Repo: https://github.com/naolson2025/bun-hono-auth 🚀 Master Hono & JWT Authentication! Build & Test Secure REST APIs from Scratch! 🚀 Ready to build robust and secure authentication for your REST APIs? This comprehensive tutorial guides you step-by-step through setting up authentication from scratch using the blazingly fast Hono.js framework, JSON Web Tokens (JWTs), and the powerful Bun JavaScript runtime. Not only will you learn to implement the core auth logic, but you'll also master writing thorough tests for every component using the Bun Test Runner, ensuring your authentication system is reliable and secure! 🔑 In this video, you will learn how to: - Understand and implement a complete token-based authentication strategy (vs. session-based). - Set up a brand new Hono application from the ground up using Bun. - Integrate SQLite for user data storage (concepts are applicable to any database) and configure it with Write-Ahead Logging (WAL) for performance. - Build essential authentication routes: - Sign Up: Register new users with email and password. - Login: Authenticate existing users. - Logout: Securely terminate user sessions. - Create protected API routes accessible only by authenticated users. - Write comprehensive unit and integration tests for your authentication logic, database queries, and API endpoints using the Bun Test Runner (including in-memory test databases for clean testing). - Generate, sign, and verify JSON Web Tokens (JWTs) for stateless authentication. - Securely store JWTs in HTTP-only cookies with essential security flags (Secure, SameSite, Path, Max-Age). - Perform robust input validation for incoming requests using Zod and Hono's Zod Validator middleware. - Securely hash and salt user passwords using Bun's built-in Bun.password functions. - Manage sensitive configurations like JWT secrets using environment variables (.env files). - Implement CSRF (Cross-Site Request Forgery) protection middleware in your Hono application. - Utilize Hono's JWT middleware for easy token verification. 🛠️ Key Technologies & Tools Covered: - Hono.js: A small, simple, and ultrafast web framework for the Edge. - Bun: An all-in-one JavaScript runtime & toolkit (includes package manager, test runner, bundler, built-in SQLite driver, and crypto functions). - JSON Web Tokens (JWT): For creating access tokens. - TypeScript: For robust and maintainable code. - SQLite: A lightweight, file-based SQL database. - Zod: TypeScript-first schema declaration and validation library. - VS Code REST Client: For manually testing API endpoints. #HonoJS #JWT #Authentication #BunJS #TypeScript #RestAPI #WebDevelopment #Security #ProgrammingTutorial #FullStack #Backend #SQLite #Zod #Testing #CSRF #DevTutorial #LearnToCode #FromScratch Chapters: 0:00 - 1:14 - Outline 1:15 - 5:43 - Explanation of Auth Strategy 5:44 - 8:08 - Setup Hono App 8:09 - 14:16 - DB Setup 14:17 - 15:50 - DB Manual Test 15:51 - 21:23 - DB insert user query 21:24 - 37:13 - DB automated testing 37:14 - 1:04:30 - Signup logic 1:04:31 - 1:22:11 - Signup automated testing 1:22:12 - 1:37:58 - Login logic 1:37:59 - 1:51:47 - Login automated testing 1:51:48 - 1:54:02 - Logout logic 1:54:03 - 1:58:30 - Logout automated testing 1:58:31 - 2:06:59 - Protected Route logic 2:07:00 - 2:10:31 - Protected Route testing
Secure APIs with These Essentials
AI-recommended products based on this video

Environet Hydroponic Growing Kit, Self-Watering Mason Jar Herb Garden Starter Kit Indoor, Windowsill Herb Garden, Grow Your Own Herbs from Organic Seeds (Basil)

Herb Garden Planter Indoor Kit 21Pcs Kitchen Herb Garden Starter Kit Growing Kit Including Wooden Box Burlap Pots Soil Discs Gardening Tools Unique Easter Birthday Christmas Gift Ideas for Women Mom

Bonsai Starter Kit – 1x Bonsai Tree | Complete Indoor Starter Kit for Growing Plants with Bonsai Seeds, Tools & Planters – Gardening Gifts for Women & Men



