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

fix: Sign up every user without check if already exist #137

Merged
merged 1 commit into from
Feb 17, 2024
Merged
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
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
Loading