experimental api changes

This commit is contained in:
2022-10-10 18:47:10 -05:00
parent 4965480aaf
commit b47730758f
4 changed files with 27 additions and 19 deletions

View File

@@ -1,5 +1,4 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { updateUser } from "./apiUtils";
import { SupabaseClient, User } from "@supabase/supabase-js";
export interface FormInput {
email: string
@@ -22,7 +21,10 @@ export const handleRegister = async (supabase: SupabaseClient | undefined, input
const { email, password } = input;
if (email && password) {
const { user, session, error} = await supabase.auth.signUp({ email, password });
if (!user) return;
if (error) throw error;
insertNewUser(user);
}
}
@@ -30,3 +32,22 @@ export const getSession = async (supabase: SupabaseClient | undefined) => {
if (!supabase) return;
console.log(supabase.auth.session());
}
export const insertNewUser = async (data: User) => {
if (!data) return;
const { email } = data;
const formattedData = {
email: email,
supabaseUser: data
}
const response = await fetch("https://mikayla-spice-market-api.com/users/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(formattedData)
})
return response;
}