-
Notifications
You must be signed in to change notification settings - Fork 1
feat: signup form functionality update #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||||||||||||||||||||||||
|
|
@@ -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; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -43,9 +43,10 @@ const schema = yup | |||||||||||||||||||||||
| .required(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const SignupForm = ({ | ||||||||||||||||||||||||
| handleSignup, | ||||||||||||||||||||||||
| socialAuth = true, | ||||||||||||||||||||||||
| socialAuth, | ||||||||||||||||||||||||
| }: SignupFormProps) => { | ||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||
| register, | ||||||||||||||||||||||||
| handleSubmit, | ||||||||||||||||||||||||
|
|
@@ -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
|
||||||||||||||||||||||||
| 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
AI
Nov 11, 2025
There was a problem hiding this comment.
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.
| setError('root.credential', { type: 'manual', message: error.message }); | |
| setError('root.credential', { type: 'manual', message: error?.message ?? "An unknown error occurred." }); |
Uh oh!
There was an error while loading. Please reload this page.