-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add Custom onboarding pages #209
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,65 @@ | ||
import { Button, Divider, Image, Input } from '@nextui-org/react'; | ||
import { GoogleOneTap, useSignIn } from '@clerk/clerk-react'; | ||
import { Link } from 'react-router-dom'; | ||
import { SignIn } from '@clerk/clerk-react'; | ||
import { reduceState } from '../shared/helpers'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useMutativeReducer } from 'use-mutative'; | ||
|
||
export default function Login() { | ||
const { | ||
register, | ||
handleSubmit, | ||
setError, | ||
formState: { errors } | ||
} = useForm(); | ||
|
||
const { isLoaded: isClerkLoaded, signIn, setActive } = useSignIn(); | ||
const [state, dispatch] = useMutativeReducer(reduceState, { | ||
isLoading: false | ||
}); | ||
|
||
const handleLogin = async data => { | ||
if (!isClerkLoaded) { | ||
return; | ||
} | ||
try { | ||
dispatch({ isLoading: true }); | ||
const signInAttempt = await signIn.create({ | ||
identifier: data.email, | ||
password: data.password | ||
}); | ||
if (signInAttempt.status === 'complete') { | ||
await setActive({ session: signInAttempt.createdSessionId }); | ||
} else { | ||
console.error(JSON.stringify(signInAttempt, null, 2)); | ||
} | ||
} catch (err) { | ||
err.errors.forEach(e => { | ||
if (e.meta.paramName === 'identifier') { | ||
setError('email', { | ||
message: e.message | ||
}); | ||
} | ||
if (e.meta.paramName === 'password') { | ||
setError('password', { | ||
message: e.message | ||
}); | ||
} | ||
}); | ||
} finally { | ||
dispatch({ isLoading: false }); | ||
} | ||
}; | ||
|
||
const handleGoogleLogin = async () => { | ||
await signIn.authenticateWithRedirect({ | ||
strategy: 'oauth_google', | ||
redirectUrl: | ||
'https://hip-primate-84.clerk.accounts.dev/v1/oauth_callback', | ||
redirectUrlComplete: '/' | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="flex h-full flex-col items-center justify-center gap-y-9"> | ||
<div className="flex flex-col gap-y-4 text-center"> | ||
|
@@ -12,44 +70,97 @@ export default function Login() { | |
Let's sign in to your account or if you don't have one, sign up | ||
</p> | ||
</div> | ||
<div className="flex flex-col items-center justify-center rounded-xl border border-outline bg-content1"> | ||
<SignIn | ||
appearance={{ | ||
layout: { | ||
socialButtonsPlacement: 'bottom' | ||
}, | ||
elements: { | ||
rootBox: 'lg:w-[31rem]', | ||
cardBox: 'lg:w-[31rem]', | ||
card: 'bg-content1 px-5', | ||
headerTitle: | ||
'text-foreground-1 text-3xl font-display font-normal', | ||
headerSubtitle: 'hidden', | ||
socialButtons: 'border rounded-md border-outline py-2', | ||
socialButtonsBlockButtonText__google: 'text-foreground-2', | ||
dividerLine: 'bg-outline', | ||
formFieldLabel: 'text-foreground-1', | ||
formFieldInput: | ||
'bg-transparent !border !border-outline text-white px-4 py-4 focus:!border-foreground-1', | ||
formFieldInputShowPasswordButton: 'text-foreground-2', | ||
formButtonPrimary: | ||
'!border bg-transparent text-secondary after:!bg-none after:border py-3 after:border-secondary hover:bg-content1 hover:border hover:border-focus hover:text-focus', | ||
footer: 'hidden', | ||
footerAction: 'bg-content1', | ||
otpCodeFieldInput: '!border !border-outline text-white', | ||
formResendCodeLink: 'text-foreground-2', | ||
backLink: 'text-foreground-2' | ||
|
||
<GoogleOneTap /> | ||
|
||
<form | ||
className="flex w-full flex-col items-center justify-center gap-y-5 rounded-lg border border-outline bg-content1 p-5 md:w-[31rem]" | ||
onSubmit={handleSubmit(handleLogin)} | ||
> | ||
<p className="font-display text-3xl text-foreground-1"> | ||
Log In to your account | ||
</p> | ||
|
||
<Input | ||
classNames={{ | ||
inputWrapper: 'rounded-sm border border-outline bg-content1', | ||
label: 'text-foreground-1', | ||
input: 'placeholder:text-foreground-2' | ||
}} | ||
errorMessage={errors.email?.message} | ||
isInvalid={!!errors.email} | ||
label="Email" | ||
name="email" | ||
placeholder="Enter your email" | ||
size="sm" | ||
variant="bordered" | ||
{...register('email', { | ||
required: 'Email is required', | ||
pattern: { | ||
value: RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm emails are notoriously hard to create a regex for. This is definitely too simple, but I guess we don't really need to do validation so strictly. If the user never receive an OTP through the email that means they have made a mistake on their end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context for the curios https://stackoverflow.com/a/201378 |
||
message: 'Enter a valid email' | ||
} | ||
})} | ||
/> | ||
|
||
<Input | ||
classNames={{ | ||
inputWrapper: 'rounded-sm border border-outline bg-content1', | ||
label: 'text-foreground-1', | ||
input: 'placeholder:text-foreground-2' | ||
}} | ||
errorMessage={errors.password?.message} | ||
isInvalid={!!errors.password} | ||
label="Password" | ||
name="password" | ||
placeholder="Enter your password" | ||
size="sm" | ||
type="password" | ||
variant="bordered" | ||
{...register('password', { | ||
required: 'Password is required', | ||
minLength: { | ||
value: 8, | ||
message: 'Password must contain 8 characters' | ||
} | ||
})} | ||
/> | ||
<p className="mb-2 text-foreground-2">Don't have an account?</p> | ||
<Link | ||
className="mb-7 cursor-pointer text-foreground-1 hover:underline" | ||
to={'/register'} | ||
|
||
<div className="flex w-full items-center gap-x-2"> | ||
<Divider className="w-[46.5%] bg-outline" /> | ||
<p>or</p> | ||
<Divider className="w-[46.5%] bg-outline" /> | ||
</div> | ||
<Button | ||
className="rounded-sm border border-outline" | ||
fullWidth | ||
onPress={handleGoogleLogin} | ||
startContent={<Image src="/images/google.svg" />} | ||
variant="bordered" | ||
> | ||
Create account | ||
</Link> | ||
</div> | ||
Continue with Google | ||
</Button> | ||
|
||
<Button | ||
className="rounded-sm border border-secondary text-secondary hover:border-focus hover:text-focus" | ||
fullWidth | ||
isLoading={state.isLoading} | ||
type="submit" | ||
variant="bordered" | ||
> | ||
Login | ||
</Button> | ||
|
||
<div className="text-center"> | ||
<p className="mb-2 text-foreground-2">Don't have an account?</p> | ||
<Link | ||
className="cursor-pointer text-foreground-1 hover:underline" | ||
to={'/register'} | ||
> | ||
Create account | ||
</Link> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} |
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.
Need to update the redirect URL with the Nethermind account redirect URL (need to setup in clerk dashboard)