-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* base for email sign up flow * CRUD and routers for EmailSignUpToken, two part register flow almost done * EmailSignUp token creation done, refined routes * fix email-signup-get and improved register UI * User creation from email sign up * redirect to login after User account creation * partial email/pass login logic * fix edge cases and type issues in API routes * Log in completed * Fix subject of registration email * fix type of /delete route for signup token * Delete signup token on registration * Actually add API key to email /login route * apparently I have to await a result I don't even care about thanks mypy * Use Google-style comments Co-authored-by: Ben Bolte <[email protected]> * email_router and google style comments * changed register to be signup * Fixed styling/linting error --------- Co-authored-by: Dennis Chen <[email protected]> Co-authored-by: Dennis Chen <[email protected]> Co-authored-by: Ben Bolte <[email protected]>
- Loading branch information
1 parent
c39cbfe
commit 328105b
Showing
17 changed files
with
710 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useAlertQueue } from "hooks/useAlertQueue"; | ||
import { useAuthentication } from "hooks/useAuth"; | ||
import { EmailSignupSchema, EmailSignupType } from "types"; | ||
|
||
import { Button } from "components/ui/Button/Button"; | ||
import ErrorMessage from "components/ui/ErrorMessage"; | ||
import { Input } from "components/ui/Input/Input"; | ||
|
||
interface EmailSignUpResponse { | ||
message: string; | ||
} | ||
|
||
const SignupWithEmail = () => { | ||
const auth = useAuthentication(); | ||
const { addAlert, addErrorAlert } = useAlertQueue(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm<EmailSignupType>({ | ||
resolver: zodResolver(EmailSignupSchema), | ||
}); | ||
|
||
const onSubmit = async ({ email }: EmailSignupType) => { | ||
const { data, error } = await auth.client.POST("/email/signup/create/", { | ||
body: { | ||
email, | ||
}, | ||
}); | ||
|
||
if (error) { | ||
addErrorAlert(error); | ||
} else { | ||
const responseData = data as EmailSignUpResponse; | ||
const successMessage = | ||
responseData?.message || | ||
"Sign up email sent! Follow the link sent to you to continue registration."; | ||
addAlert(successMessage, "success"); | ||
} | ||
}; | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit(onSubmit)} | ||
className="grid grid-cols-1 space-y-6" | ||
> | ||
{/* Email Input */} | ||
<div className="relative"> | ||
<Input placeholder="Email" type="text" {...register("email")} /> | ||
{errors?.email && <ErrorMessage>{errors?.email?.message}</ErrorMessage>} | ||
</div> | ||
{/* Signup Button */} | ||
<Button | ||
variant="outline" | ||
className="w-full text-white bg-blue-600 hover:bg-opacity-70" | ||
> | ||
Sign up with email | ||
</Button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default SignupWithEmail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.