Skip to content

Commit

Permalink
fixed signup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-Roberts123 committed May 3, 2024
1 parent 7c3ceff commit 439ac0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
22 changes: 3 additions & 19 deletions src/app/auth/sign-up/components/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import PasswordInput from "@/components/ui/password-input";
import FormWrapper from "../../components/FormWrapper";
import { env } from "@/lib/env";
import { useRouter } from "next/navigation";
import { signIn } from "next-auth/react";

export function SignUpForm() {
const { toast } = useToast();
Expand All @@ -46,26 +45,11 @@ export function SignUpForm() {
if (res.ok) {
const data = await res.json();
toast({
title: "Registration success:",
description: <h3>User was created successfully</h3>,
title: "Registration was successfull:",
description: <h3>Please Login with your credentials</h3>,
});

const resSignin = await signIn("credentials", {
email: data.email,
password: data.password,
callbackUrl: `${env.NEXT_PUBLIC_WEBAPPURL}`,
redirect: false,
});

if (!resSignin?.ok) {
toast({
variant: "destructive",
title: "Login failed:",
description: <h3>Could not login a user, check your credentials</h3>,
});
} else {
router.push("/");
}
router.push("/auth/sign-in");
} else {
toast({
variant: "destructive",
Expand Down
2 changes: 1 addition & 1 deletion src/app/clients/components/client-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const ClientForm = ({
)}
/>
</div>
<FormDescription className="col-span-5">
<FormDescription className="md:col-span-5">
Client information.
</FormDescription>
</div>
Expand Down
24 changes: 15 additions & 9 deletions src/lib/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import prisma from "../prisma";
import { exclude, hashText } from "../utils";
import { TUser } from "../types";

export async function getUser(email: string) {
const user = await prisma.user.findUnique({
where: { email: email },
select: {
id: true,
username: true,
email: true,
password: true,
},
});

return user;
}

export async function loginUserHandler({
email,
password,
Expand All @@ -10,15 +24,7 @@ export async function loginUserHandler({
password: string;
}): Promise<TUser> {
try {
const user = await prisma.user.findUnique({
where: { email: email },
select: {
id: true,
username: true,
email: true,
password: true,
},
});
const user = await getUser(email);
if (user && user.password === hashText(password)) {
return exclude(user, ["password"]);
} else {
Expand Down

0 comments on commit 439ac0c

Please sign in to comment.