Skip to content

Commit

Permalink
separated pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Yo-mah-Ya committed Nov 25, 2023
1 parent ba46e7a commit 0a0674f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use server'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
import { createClient } from '../supabase'
import { createClient } from '../../supabase'
import type { SignUpSchema } from './page'

export const signUp = async ({
Expand Down
83 changes: 83 additions & 0 deletions app/auth/signup/email/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use client'
import { startTransition } from 'react'
import { useForm } from 'react-hook-form'
import { Flex, Heading } from '@chakra-ui/react'
import * as z from 'zod'
import { PrimaryButton } from '@/components/button'
import { signUp } from './action'

const signUpSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
confirmationPassword: z.string().min(8)
})
export type SignUpSchema = z.infer<typeof signUpSchema>

export default function SignUp() {
const {
register,
handleSubmit,
setError,
formState: { errors }
} = useForm<SignUpSchema>()
return (
<>
<Heading>Welcome!</Heading>
<Heading>Create an Account</Heading>
<form
onSubmit={handleSubmit((data) => {
const result = signUpSchema.safeParse(data)
if (!result.success) {
console.error(result.error)
return
}

if (result.data.password !== result.data.confirmationPassword) {
setError('confirmationPassword', {
message: 'Your password and confirmation password must match'
})
}
startTransition(() => {
signUp(result.data).catch(console.error)
})
})}
>
<Flex flexDirection={'column'}>
<label htmlFor="email">Email address</label>
<input type="email" id="email" required {...register('email')} />
<label htmlFor="password">Password</label>
<input
type="password"
id="password"
required
{...register('password', {
minLength: {
value: 8,
message: 'min length is 8'
}
})}
/>
{errors.password && (
<span role="alert">{errors.password.message}</span>
)}
<label htmlFor="re-type-password">Confirmation Password</label>
<input
type="password"
id="re-type-password"
required
{...register('confirmationPassword', {
minLength: {
value: 8,
message: 'min length is 8'
}
})}
/>
{errors.confirmationPassword && (
<span role="alert">{errors.confirmationPassword.message}</span>
)}
<PrimaryButton type={'submit'}>Sign Up</PrimaryButton>
</Flex>
</form>
</>
)
}
67 changes: 27 additions & 40 deletions app/auth/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
'use client'
import { startTransition } from 'react'
import { useForm } from 'react-hook-form'
import { Flex, Heading } from '@chakra-ui/react'
import * as z from 'zod'
import { PrimaryButton } from '@/components/button'
import { signUp } from './action'

const signUpSchema = z.object({
email: z.string().email(),
password: z.string()
})
export type SignUpSchema = z.infer<typeof signUpSchema>
import { Heading, List, ListItem } from '@chakra-ui/react'
import Link from 'next/link'
import { SecondaryButton } from '@/components/button'

export default function SignUp() {
const { register, handleSubmit } = useForm()
return (
<>
<Heading>SignUp Page</Heading>
<form
onSubmit={handleSubmit((data) => {
const result = signUpSchema.safeParse(data)
if (!result.success) {
console.error(result.error)
return
}
startTransition(() => {
signUp(result.data).catch(console.error)
})
})}
>
<Flex flexDirection={'column'}>
<label htmlFor="email">Email</label>
<input type="email" id="email" required {...register('email')} />
<label htmlFor="password">Password</label>
<input
type="password"
id="password"
required
{...register('password')}
/>
<PrimaryButton type={'submit'}>Sign Up</PrimaryButton>
</Flex>
</form>
<Heading>Welcome!</Heading>
<Heading>Create an Account</Heading>
<List spacing={3}>
<ListItem>
<Link href="/auth/signup/email">
<SecondaryButton>Sign up with Email</SecondaryButton>
</Link>
</ListItem>
<ListItem>
<Link href="/auth/signup/google">
<SecondaryButton>Sign up with Google</SecondaryButton>
</Link>
</ListItem>
<ListItem>
<Link href="/auth/signup/facebook">
<SecondaryButton>Sign up with Facebook</SecondaryButton>
</Link>
</ListItem>
<ListItem>
<Link href="/auth/signup/apple">
<SecondaryButton>Sign up with Apple</SecondaryButton>
</Link>
</ListItem>
</List>
</>
)
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"react-icons": "^4.12.0",
"sb": "^7.5.3",
"storybook": "^7.5.3",
"supabase": "1.112.0",
"typescript": "^5",
"zod": "^3.22.4"
}
Expand Down
89 changes: 0 additions & 89 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a0674f

Please sign in to comment.