22
loading...
This website collects cookies to deliver better user experience
npm init @vitejs/app
cd *your project name*
npm install
npm run dev
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
tailwind.config.js
& postcss.config.js
files automatically.npx tailwindcss init -p
style.css
file. Tailwind will start working perfectly.@tailwind base;
@tailwind components;
@tailwind utilities;
npm install @supabase/supabase-js
.env
file in your project's directory and copy your anon key
and supabase URL
and paste it in your .env
file as I have done below.VITE_SUPABASE_URL=YOUR_SUPABASE_URL
VITE_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
supabase.js
file in your project's directory and paste the following commands.import { createClient } from '@supabase/supabase-js'
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
export const supabase = createClient(supabaseUrl, supabaseAnonKey)
index.html
and main.js
files and run them on your machine.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div class="p-5">
<div id="blogs" class="mb-6"></div>
<form id="form">
<input
class="border-2 border-black mb-2"
type="text"
placeholder="Title of the blog"
id="title"
/>
<br />
<textarea
class="border-2 border-black mb-2"
placeholder="Description of the blog"
id="content"
></textarea>
<br />
<button class="bg-blue-400 p-1 text-white" type="submit">Submit</button>
</form>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>
const { data, error } = await supabase.from("blogs").select();
gets all the data from supabase and const { data, error } = await supabase.from("blogs").insert([{ title: title.value,content: content.value },]);
insert the data into our table.import "./style.css";
import { supabase } from "./supabase";
const blogsContainer = document.getElementById("blogs");
const form = document.getElementById("form");
const title = document.getElementById("title");
const content = document.getElementById("content");
const useData = async () => {
const { data, error } = await supabase.from("blogs").select(); // gets the data from supabase
let html = "";
data.forEach((blog) => {
html += `
<div data-id="${blog.id}">
<h1 class="text-2xl">${blog.title}</h1>
<p>${blog.content}</p>
</div>
`;
});
blogsContainer.innerHTML = html;
};
window.addEventListener("DOMContentLoaded", useData);
form.addEventListener("submit", async (e) => {
e.preventDefault();
const { data, error } = await supabase.from("blogs").insert([
{
title: title.value,
content: content.value,
},
]); // insert data into supabase
useData();
});
index.html
& main.js
code and run it on your machine.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div class="p-5">
<div>
<h1 class="text-3xl text-center mb-4">Sign Up</h1>
</div>
<form id="form">
<input
class="border-2 border-black mb-2 p-1"
type="email"
placeholder="Email Address"
id="email"
autocomplete="off"
/>
<br />
<input
type="password"
placeholder="Password"
id="password"
class="border-2 border-black mb-2 p-1"
/>
<br />
<button class="bg-blue-400 p-1 text-white" type="submit">Submit</button>
</form>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>
const { user, session, error } = await supabase.auth.signUp({ email: email.value, password: password.value });
signUp users. NOTE: IF YOU ARE NOT DISABLING EMAIL CONFIRMATION THEN THE SESSION VALUE WILL BE NULLimport "./style.css";
import { supabase } from "./supabase";
const form = document.getElementById("form");
const email = document.getElementById("email");
const password = document.getElementById("password");
form.addEventListener("submit", async (e) => {
e.preventDefault();
const { user, session, error } = await supabase.auth.signUp({
email: email.value,
password: password.value,
});
console.log(user, session, error);
form.reset();
});