Skip to content

Commit

Permalink
Merge pull request #137 from LuizLimaDev/fix/signUp
Browse files Browse the repository at this point in the history
fix: Sign up every user without check if already exist
  • Loading branch information
LuizLimaDev authored Feb 17, 2024
2 parents e1c4217 + 86152cb commit 3e09437
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/app/(auth-routes)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,31 @@ import { redirect } from "next/navigation";

export default async function SignIn({ children }: TChildrenProps) {
const session = await getServerSession(authOptions);
const userData = {
name: session?.user.name,
email: session?.user.email,
phone: null,
password: null,
};

async function signUpNewUser() {
const { error } = await supabase.from("users").insert(userData);

if (session) {
const userData = {
name: session.user.name,
email: session.user.email,
phone: null,
password: null,
};
if (error) {
return Response.json(error);
}

console.log("cadastrando USUARIO!");
}

if (session) {
const { data } = await supabase.from("users").select();

const emailVerification = data?.some(
(user) => user.email === userData.email
);

if (emailVerification) {
console.log("Cadastrando novo USUARIO!");
redirect("/home");
return;
}

const { error } = await supabase.from("users").insert(userData);

if (error) {
return Response.json(error);
}
!emailVerification && signUpNewUser();

redirect("/home");
}
Expand Down

0 comments on commit 3e09437

Please sign in to comment.