π₯ 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.
Tech Stack :
π₯ 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.
Installation π
After cloning the repository, install the necessary dependencies by running:
Configuration β¨
Edit the file to include the necessary environment variables:
Structure π
Usage π»
To start the server, run:
Deploy the server to Cloudfare Workers by running:
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.
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.
Supabase Client Usage β‘οΈ
The project uses two Supabase clients: and . These clients are created in the function in src/db/supabaseClient.ts.
The client is used for operations that do not require elevated privileges. It is created using the anonymous key () and is configured to not automatically refresh tokens, persist sessions, or detect sessions in URLs.
Example usage:
The client is used for operations that require elevated privileges, such as authentication and user management. It is created using the service key ().
Example usage:
License
This project is licensed under the MIT License - see the LICENSE file for details.