Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add supabase #1

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default function Login() {

const completeLogin = async(e) => {
const { userId, token, userCredentials } = e;

// store email in supabase
// await generalFunction.supabase_addData("users", userCredentials);

if (userId && token) {
localStorage.setItem("questUserId", userId);
localStorage.setItem("questUserToken", token);
Expand Down
11 changes: 10 additions & 1 deletion src/Components/Onboarding/Onboarding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ export default function Onboarding() {
const { theme, bgColors, contentConfig } = useContext(ThemeContext);
const [key, setKey] = useState("");

const completeAnswer = (e) => {
const completeAnswer = async(e) => {
// await generalFunction.supabase_updateData(
// "users",
// generalFunction.getUserCredentials()?.email,
// {
// // for storing the data in supabase add the following key and value
// // eg. name: answer["ec-cf14a2e1-9ea5-448f-aaa4-d6f866a853e9"]
// }
// );

navigate("/dashboard");
};

Expand Down
2 changes: 2 additions & 0 deletions src/assets/Config/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const mainConfig = {
GOOGLE_REDIRECT_URI: "https://quest-dashboard-starter-template-26sa.vercel.app/",
GOOGLE_CLIENT_ID: "48459226857-eobo616j32erioo3dab9nid98fmvjom7.apps.googleusercontent.com",
CONTACT_EMAIL: "",
REACT_APP_SUPABASE_URL: "",
REACT_APP_SUPABASE_ANON_KEY: "",
}
32 changes: 32 additions & 0 deletions src/assets/Config/generalFunction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,37 @@ export const generalFunction = {
} catch (error) {
return { success: false, loginAgain: true };
}
},

supabase_addData: async (table, rowData) => {
const { data, error } = await supabase.from(table).select('*').eq("email", rowData.email).maybeSingle();
if (error) {
throw error;
}

if (!data || !data?.email) {
const { data: newUserData, error: insertError } = await supabase
.from(table)
.insert([{
email: rowData.email,
...(!!rowData?.name && { name: rowData?.name }),
}])
.select();
if (insertError) {
throw insertError;
}
}
},

supabase_updateData: async (table, email, rowData) => {
const { data, error } = await supabase
.from(table)
.update(rowData)
.eq("email", email)
.select()

if (error) {
throw error;
}
}
}
7 changes: 7 additions & 0 deletions src/supabaseClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createClient } from "@supabase/supabase-js";
import { mainConfig } from "./assets/Config/appConfig";

const supabaseUrl = mainConfig.REACT_APP_SUPABASE_URL;
const supabaseKey = mainConfig.REACT_APP_SUPABASE_ANON_KEY;

export const supabase = createClient(supabaseUrl, supabaseKey);