Back to log in link
Auth
Ready to use authentication forms.
Import#
Auth
: Higher order component responsible for rendering all specific auth forms.AuthForm
: Composes login and signup forms with a title and oauth providers.MagicLoginForm
: Basic magic link login form.PasswordForm
: Basic email and password form.ForgotPasswordForm
: Basic forgot password form.UpdatePasswordForm
: Basic update password form.OtpForm
: Basic one time password form.Providers
: Oauth provider login buttons.
import {Auth,AuthForm,MagicLinkForm,PasswordForm,ForgotPasswordForm,UpdatePasswordForm,OtpForm,Providers,} from '@saas-ui/react'
Usage#
Auth
is an higher order component that handles the rendering of all the specific authentication forms.
If you need more flexiblity it's possible to use these components directly.
Auth
depends on context provided by AuthProvider
, if you haven't done so already, first add it to your App root.
Basic usage#
The default authentication strategy is magiclink
.
<Stack maxW="400px"><Auth /></Stack>
Password login#
<Stack maxW="400px"><Auth type="password" /></Stack>
Social login#
<Stack maxW="400px"><Authproviders={{github: {icon: FaGithub,name: 'Github',},}}/></Stack>
Sign up#
<Stack maxW="400px"><Auth view="signup" /></Stack>
One time password#
<Stack maxW="400px"><Auth view="otp" /></Stack>
Custom links#
<Stack maxW="400px" alignSelf="center"><AuthsignupLink={<Link href="/signup">Sign up</Link>}loginLink={<Link href="/login">Log in</Link>}/></Stack>
Custom log in page#
function LoginPage() {return (<Card title="Welcome to Saas UI"><CardBody><PasswordForm action="logIn" submitLabel="Log in" /></CardBody></Card>)}
Custom sign up page#
function SignUpPage() {return (<Card title="Sign up for free"><CardBody><PasswordForm action="signUp" submitLabel="Sign up"><FormLayout columns={2}><Field name="firstName" label="First name" /><Field name="lastName" label="Last name" /></FormLayout><Field name="company" label="Company" /></PasswordForm></CardBody></Card>)}
Schema validation#
function LoginPage() {const schema = Yup.object({email: Yup.string().email('Invalid email address').required().label('Email'),password: Yup.string().min(4).required().label('Password'),})return (<PasswordFormaction="logIn"submitLabel="Log in"resolver={yupResolver(schema)}/>)}
Props#
Auth Props#
backLink
backLink
ReactNode
"Back to log in"
children
children
Children are passed down to the underlying form
ReactNode
context
context
any
criteriaMode
criteriaMode
CriteriaMode
delayError
delayError
number
dividerLabel
dividerLabel
Label for the divider between oath and the form
string
"or continue with"
footer
footer
Render custom elements under the submit button
ReactNode
forgotLink
forgotLink
The forgot password link
ReactNode
"Forgot password?"
formRef
formRef
Ref on the HTMLFormElement.
RefObject<HTMLFormElement>
haveAccount
haveAccount
Text shown before the loginLink
ReactNode
"Already have an account?"
loginLink
loginLink
Customize the login link under the sign up form.
ReactNode
"Log in"
mode
mode
keyof ValidationMode
noAccount
noAccount
Text shown before the signupLink
ReactNode
"No account?"
onChange
onChange
Triggers when any of the field change.
WatchObserver<any>
onError
onError
Error handler if login or signup fails
((error: Error) => void)
onSuccess
onSuccess
Callback executed after succesful login or signup
((data: any) => void)
onValidationError
onValidationError
Callback executed when there are validation errors
((errors: Partial<FieldErrorsImpl<{ [x: string]: any; }>>) => void)
providerLabel
providerLabel
Label for the provider buttons
string
"Continue with"
providers
providers
The OAuth providers that are supported.
AvailableProviders
resolver
resolver
Resolver<any, any>
reValidateMode
reValidateMode
"onBlur" | "onChange" | "onSubmit"
schema
schema
The form schema, currently supports Yup schema only.
any
shouldFocusError
shouldFocusError
boolean
shouldUnregister
shouldUnregister
boolean
shouldUseNativeValidation
shouldUseNativeValidation
boolean
signupLink
signupLink
Customize the signup link under the log in form.
ReactNode
"Sign up"
submitLabel
submitLabel
Label for the submit button
string
"Sign in"
title
title
The form title
ReactNode
type
type
The authentication type, magiclink
or password
AuthTypeEnum
view
view
Sets the visible authentication form. Supported views are: - login - signup - forgot_password - update_password - otp
ViewType
Was this helpful?