Skip to content
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
14 changes: 1 addition & 13 deletions apps/client/src/app/auth/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
'use client';

import { authClient } from '@/auth';
import SignupForm from 'components/sections/authentications/default/SignupForm';

const Page = () => {
const handleSignup = async (data: { name: string; email: string; password: string }) => {
const { data: loginData, error } = await authClient.signUp.email({
email: data.email,
password: data.password,
name: data.name,
});
console.log(loginData, error);
};

return <SignupForm handleSignup={handleSignup} socialAuth />;
return <SignupForm socialAuth={true} />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { yupResolver } from "@hookform/resolvers/yup";
import {
Alert,
Box,
Expand All @@ -11,17 +10,18 @@ import {
TextField,
Typography,
} from "@mui/material";
import * as yup from "yup";
import { authClient } from "@/auth";
import Grid from "@mui/material/Grid";
import SocialAuth from "./SocialAuth";
import { useForm } from "react-hook-form";
import { useRouter } from "next/navigation";
import paths, { rootPaths } from "routes/paths";
import IconifyIcon from "components/base/IconifyIcon";
import { yupResolver } from "@hookform/resolvers/yup";
import PasswordTextField from "components/common/PasswordTextField";

import { useForm } from "react-hook-form";
import paths from "routes/paths";
import * as yup from "yup";
import SocialAuth from "./SocialAuth";

interface SignupFormProps {
handleSignup: (data: SignupFormValues) => Promise<any | undefined>;
socialAuth?: boolean;
}

Expand All @@ -43,9 +43,10 @@ const schema = yup
.required();

const SignupForm = ({
handleSignup,
socialAuth = true,
socialAuth,
}: SignupFormProps) => {
const router = useRouter();

const {
register,
handleSubmit,
Expand All @@ -56,12 +57,18 @@ const SignupForm = ({
});

const onSubmit = async (data: SignupFormValues) => {
await handleSignup(data).catch((error: any) => {
if (error) {
console.log(error, "error");
setError("root.credential", { type: "manual", message: error.message });
}
const { data: signupData, error } = await authClient.signUp.email({
email: data.email,
password: data.password,
name: data.name,
});

if (signupData) {
router.push(rootPaths.root);
}
if (error) {
setError('root.credential', { type: 'manual', message: error.message });
Comment on lines +66 to +70
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both success and error conditions can be true simultaneously if signupData exists but error is also present. These should be mutually exclusive using else-if logic to prevent navigating away while also setting an error.

Suggested change
if (signupData) {
router.push(rootPaths.root);
}
if (error) {
setError('root.credential', { type: 'manual', message: error.message });
if (error) {
setError('root.credential', { type: 'manual', message: error.message });
} else if (signupData) {
router.push(rootPaths.root);

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error if error.message is undefined. The error object should be checked for the existence of the message property before accessing it, or provide a fallback error message.

Suggested change
setError('root.credential', { type: 'manual', message: error.message });
setError('root.credential', { type: 'manual', message: error?.message ?? "An unknown error occurred." });

Copilot uses AI. Check for mistakes.
}
};

return (
Expand Down Expand Up @@ -197,11 +204,13 @@ const SignupForm = ({
</Grid>
<Grid size={12}>
<Button
loading={isSubmitting}
fullWidth
type='submit'
size='large'
variant='contained'>
type="submit"
size="large"
variant="contained"
loading={isSubmitting}
loadingPosition="start"
>
Create Account
</Button>
</Grid>
Expand Down