Skip to content

This project is a backend boilerplate built using the Hono framework. Cloudfare Workers are used to host the backend. It includes integration with Supabase and handles user authentication and authorization.

License

Notifications You must be signed in to change notification settings

goktugcy/hono-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔥 Hono + ⚡️ Supabase Boilerplate

This project is a backend boilerplate built using the Hono framework. Cloudfare Workers are used to host the backend. It includes integration with Supabase and handles user authentication and authorization.

code style: prettier MIT License GitHub Created At GitHub Repo stars GitHub forks

Installation 🚀

After cloning the repository, install the necessary dependencies by running:

bun install

Configuration ✨

Edit the .wrangler.toml file to include the necessary environment variables:

STAGE = "dev" # dev or prod
# Supabase
SUPABASE_URL=
SUPABASE_SERVICE_KEY=
SUPABASE_ANON_KEY=

Structure 🎄

.
├── src
│   ├── controllers
│   │   ├── AuthController.ts
│   │   ├── CountryController.ts
│   ├── middlewares
│   │   ├── authMiddleware.ts
│   ├── db
│   │   ├── supabaseClient.ts
│   ├── routes.ts
│   ├── helpers.ts
├── index.ts
├── wrangler.toml
├── package.json
├── README.md
├── tsconfig.json
├── .gitignore
├── bun.lockb

Usage 🍻

To start the server, run:

bun dev

Deploy the server to Cloudfare Workers by running:

bun run deploy

Authentication 🛡

The boilerplate includes an authentication middleware that checks if the user is authenticated. The middleware is used in the routes.ts file to protect routes that require authentication.

import { authMiddleware } from './middlewares/authMiddleware';

router.get('/countries', authMiddleware, CountryController.index);

Token Extraction: The middleware extracts the accessToken and refreshToken from the request cookies.

Token Verification:

  • If the accessToken is expired but the refreshToken is valid, it requests a new accessToken using the refreshToken.
  • If both tokens are missing, it responds with an error.
  • If the accessToken is present, it verifies the token using Supabase's authentication service.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This project is a backend boilerplate built using the Hono framework. Cloudfare Workers are used to host the backend. It includes integration with Supabase and handles user authentication and authorization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published