Skip to content

Commit

Permalink
articles: supabase and web 3
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamankoji committed Jun 26, 2024
1 parent d032545 commit d13e8e6
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 13 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
242 changes: 242 additions & 0 deletions content/articles/supabase-introduction/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
---
title: "Supabase: The Open Source Firebase Alternative"
description: Supabase is an open-source Firebase alternative that provides a suite of tools for building scalable applications without the need to write a backend. It leverages PostgreSQL for real-time databases, offers authentication, and file storage capabilities. Supabase aims to democratize backend development by providing a modern, scalable, and open-source platform.
author: Lohith Lalam
lastmod: 2023-06-15
publishdate: 2023-06-15
tags:
- supabase
- database
- introduction

draft: false
---

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Introduction](#introduction)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Steps](#steps)
- [Tutorial with an Example Project](#tutorial-with-an-example-project)
- [Example Project: Todo List Application](#example-project-todo-list-application)
- [Steps](#steps-1)
- [Features and Links](#features-and-links)
- [List of Projects to Do Using Supabase](#list-of-projects-to-do-using-supabase)
- [List of Projects That Use Supabase](#list-of-projects-that-use-supabase)
- [Making the Best of Supabase](#making-the-best-of-supabase)
- [Conclusion](#conclusion)

## Introduction

Supabase is an open-source Firebase alternative that provides a suite of tools for building scalable applications without the need to write a backend. It leverages PostgreSQL for real-time databases, offers authentication, and file storage capabilities. Supabase aims to democratize backend development by providing a modern, scalable, and open-source platform.

## Setup

### Prerequisites

- Node.js installed on your computer.
- A web browser.
- A text editor or IDE like VSCode.

### Steps

1. **Sign Up for Supabase**
- Visit [Supabase](https://supabase.io) and sign up for a free account.
- Once logged in, create a new project.

2. **Create a New Project**
- In the Supabase dashboard, click on "New Project".
- Provide a name for your project, choose a database password, and select a region.

<div align="center">

![Supabase Dashboard - Create New Project](https://supabase.com/_next/image?url=%2Fimages%2Fblog%2Flaunch-week-three%2Fstudio%2Fopen-source-studio-thumb.png&w=640&q=100)
</div>

3. **Configure Your Database**
- After creating the project, you’ll be directed to the project’s overview page.
- Note down the API URL and the API key, as you’ll need these for your frontend application.

## Tutorial with an Example Project

### Example Project: Todo List Application

In this tutorial, we’ll build a simple Todo List application using Supabase and React.

### Steps

1. **Initialize a React Application**
- Open your terminal and run the following command to create a new React application:

```bash
npx create-react-app supabase-todo
cd supabase-todo
```

2. **Install Supabase Client**
- Inside your React project directory, install the Supabase client:

```bash
npm install @supabase/supabase-js
```

3. **Set Up Supabase Client**
- Create a new file named `supabaseClient.js` in the `src` directory and add the following code:

```javascript
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = 'https://your-supabase-url.supabase.co';
const supabaseKey = 'your-anon-key';
export const supabase = createClient(supabaseUrl, supabaseKey);
```
4. **Create a Database Table**
- In the Supabase dashboard, go to the SQL editor and run the following SQL to create a `todos` table:
```sql
create table todos (
id bigint generated by default as identity primary key,
task text not null,
is_complete boolean default false
);
```
5. **Fetch Todos from Supabase**
- In your `App.js` file, import Supabase and fetch the todos:
```javascript
import React, { useState, useEffect } from 'react';
import { supabase } from './supabaseClient';
function App() {
const [todos, setTodos] = useState([]);
useEffect(() => {
fetchTodos();
}, []);
const fetchTodos = async () => {
let { data: todos, error } = await supabase
.from('todos')
.select('*');
if (error) console.log('Error:', error);
else setTodos(todos);
};
return (
<div className="App">
<h1>Todo List</h1>
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.task}</li>
))}
</ul>
</div>
);
}
export default App;
```
6. **Add a New Todo**
- Add a form to your `App.js` to allow adding new todos:
```javascript
function App() {
const [todos, setTodos] = useState([]);
const [task, setTask] = useState('');
useEffect(() => {
fetchTodos();
}, []);
const fetchTodos = async () => {
let { data: todos, error } = await supabase
.from('todos')
.select('*');
if (error) console.log('Error:', error);
else setTodos(todos);
};
const addTodo = async (task) => {
let { data: todo, error } = await supabase
.from('todos')
.insert([{ task }]);
if (error) console.log('Error:', error);
else fetchTodos();
};
return (
<div className="App">
<h1>Todo List</h1>
<form onSubmit={(e) => {
e.preventDefault();
addTodo(task);
setTask('');
}}>
<input
type="text"
value={task}
onChange={(e) => setTask(e.target.value)}
placeholder="Add a new task"
/>
<button type="submit">Add</button>
</form>
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.task}</li>
))}
</ul>
</div>
);
}
export default App;
```
<div align="center">
![Supabase Todo List App](https://supabase.com/_next/image?url=%2Fimages%2Fproduct%2Fdatabase%2Fheader--light-2.png&w=3840&q=75)
</div>
## Features and Links
Supabase offers various features including:
- **Real-Time Database**: Based on PostgreSQL with real-time capabilities.
- **Authentication**: Support for multiple authentication methods.
- **File Storage**: Secure storage for large files.
- **API Generation**: Automatic RESTful API generation.
For more detailed information and guides, visit the [Supabase documentation](https://supabase.io/docs).
## List of Projects to Do Using Supabase
- **Chat Application**: Real-time messaging with user authentication.
- **E-commerce Platform**: Product listings, user accounts, and real-time inventory management.
- **Project Management Tool**: Collaborative project management with real-time updates.
- **Social Media App**: User profiles, posts, and comments with real-time interactions.
## List of Projects That Use Supabase
- **[GitHub Finder](https://github.com/yourgithubusername/github-finder)**
- **[Real-Time Chat](https://github.com/yourgithubusername/realtime-chat)**
- **[Task Manager](https://github.com/yourgithubusername/task-manager)**
- **[E-commerce Store](https://github.com/yourgithubusername/ecommerce-store)**
## Making the Best of Supabase
- **Utilize Real-Time Features**: Leverage real-time capabilities for interactive applications.
- **Secure Authentication**: Implement robust user authentication and authorization workflows.
- **Explore Supabase Community**: Engage with the community for support, ideas, and collaboration.
- **Stay Updated**: Keep an eye on new features and updates from the Supabase team.
## Conclusion
Supabase is a powerful and open-source alternative to Firebase, offering real-time databases, authentication, and file storage with the robustness of PostgreSQL. Its ease of integration, scalability, and cost-effective pricing make it an excellent choice for modern application development.
By following this guide, you can quickly get started with Supabase and build a variety of applications efficiently. Explore the Supabase ecosystem and leverage its capabilities to create innovative and responsive applications.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading

0 comments on commit d13e8e6

Please sign in to comment.