Skip to main content
Have a Wasp app in production? 🐝 We'll send you some swag! πŸ‘•
Version: 0.20.0

Auth UI

To make using authentication in your app as easy as possible, Wasp generates the server-side code but also the client-side UI for you. It enables you to quickly get the login, signup, password reset and email verification flows in your app.

Below we cover all of the available UI components and how to use them.

[画像:Auth UI]

note

Remember that if you need a more custom approach, you can always create your own UI.

Overview​

After Wasp generates the UI components for your auth, you can use it as is, or customize it to your liking.

Based on the authentication providers you enabled in your main.wasp file, the Auth UI will show the corresponding UI (form and buttons). For example, if you enabled e-mail authentication:

  • JavaScript
  • TypeScript
main.wasp
appMyApp{
//...
auth: {
methods: {
email: {},
},
// ...
}
}

You'll get the following UI:

[画像:Auth UI]

And then if you enable Google and Github:

  • JavaScript
  • TypeScript
main.wasp
appMyApp{
//...
auth: {
methods: {
email: {},
google: {},
github: {},
},
// ...
}
}

The form will automatically update to look like this:

[画像:Auth UI]

Let's go through all of the available components and how to use them.

Auth Components​

The following components are available for you to use in your app:

Login Form​

Used with Username & Password, Email, Github, Google, Keycloak, Slack and Discord authentication.

[画像:Login form]

You can use the LoginForm component to build your login page:

  • JavaScript
  • TypeScript
main.wasp
// ...

routeLoginRoute{path: "/login",to: LoginPage}
pageLoginPage{
component: import{LoginPage}from"@src/LoginPage"
}
src/LoginPage.jsx
import{LoginForm}from'wasp/client/auth'

// Use it like this
exportfunctionLoginPage(){
return<LoginForm/>
}

It will automatically show the correct authentication providers based on your main.wasp file.

Signup Form​

Used with Username & Password, Email, Github, Google, Keycloak, Slack and Discord authentication.

[画像:Signup form]

You can use the SignupForm component to build your signup page:

  • JavaScript
  • TypeScript
main.wasp
// ...

routeSignupRoute{path: "/signup",to: SignupPage}
pageSignupPage{
component: import{SignupPage}from"@src/SignupPage"
}
src/SignupPage.jsx
import{SignupForm}from'wasp/client/auth'

// Use it like this
exportfunctionSignupPage(){
return<SignupForm/>
}

It will automatically show the correct authentication providers based on your main.wasp file.

Read more about customizing the signup process like adding additional fields or extra UI in the Auth Overview section.

Forgot Password Form​

Used with Email authentication.

If users forget their password, they can use this form to reset it.

[画像:Forgot password form]

You can use the ForgotPasswordForm component to build your own forgot password page:

  • JavaScript
  • TypeScript
main.wasp
// ...

routeRequestPasswordResetRoute{path: "/request-password-reset",to: RequestPasswordResetPage}
pageRequestPasswordResetPage{
component: import{ForgotPasswordPage}from"@src/ForgotPasswordPage"
}
src/ForgotPasswordPage.jsx
import{ForgotPasswordForm}from'wasp/client/auth'

// Use it like this
exportfunctionForgotPasswordPage(){
return<ForgotPasswordForm/>
}

Reset Password Form​

Used with Email authentication.

After users click on the link in the email they receive after submitting the forgot password form, they will be redirected to this form where they can reset their password.

[画像:Reset password form]

You can use the ResetPasswordForm component to build your reset password page:

  • JavaScript
  • TypeScript
main.wasp
// ...

routePasswordResetRoute{path: "/password-reset",to: PasswordResetPage}
pagePasswordResetPage{
component: import{ResetPasswordPage}from"@src/ResetPasswordPage"
}
src/ResetPasswordPage.jsx
import{ResetPasswordForm}from'wasp/client/auth'

// Use it like this
exportfunctionResetPasswordPage(){
return<ResetPasswordForm/>
}

Verify Email Form​

Used with Email authentication.

After users sign up, they will receive an email with a link to this form where they can verify their email.

[画像:Verify email form]

You can use the VerifyEmailForm component to build your email verification page:

  • JavaScript
  • TypeScript
main.wasp
// ...

routeEmailVerificationRoute{path: "/email-verification",to: EmailVerificationPage}
pageEmailVerificationPage{
component: import{VerifyEmailPage}from"@src/VerifyEmailPage"
}
src/VerifyEmailPage.jsx
import{VerifyEmailForm}from'wasp/client/auth'

// Use it like this
exportfunctionVerifyEmailPage(){
return<VerifyEmailForm/>
}

Customization πŸ’…πŸ»β€‹

You customize all of the available forms by passing props to them.

Props you can pass to all of the forms:

  1. appearance - customize the form colors (via design tokens)
  2. logo - path to your logo
  3. socialLayout - layout of the social buttons, which can be vertical or horizontal

1. Customizing the Colors​

We use CSS variables in our styling so you can customize the styles by overriding the default theme tokens.

List of all available tokens

See the list of all available tokens which you can override.

  • JavaScript
  • TypeScript
src/appearance.js
exportconst authAppearance ={
colors:{
brand:'#5969b8',// blue
brandAccent:'#de5998',// pink
submitButtonText:'white',
},
}
src/LoginPage.jsx
import{LoginForm}from'wasp/client/auth'
import{ authAppearance }from'./appearance'

exportfunctionLoginPage(){
return(
<LoginForm
// Pass the appearance object to the form
appearance={authAppearance}
/>
)
}

We recommend defining your appearance in a separate file and importing it into your components.

You can add your logo to the Auth UI by passing the logo prop to any of the components.

  • JavaScript
  • TypeScript
src/LoginPage.jsx
import{LoginForm}from'wasp/client/auth'
importLogofrom'./logo.png'

exportfunctionLoginPage(){
return(
<LoginForm
// Pass in the path to your logo
logo={Logo}
/>
)
}

3. Social Buttons Layout​

You can change the layout of the social buttons by passing the socialLayout prop to any of the components. It can be either vertical or horizontal (default).

If we pass in vertical:

  • JavaScript
  • TypeScript
src/LoginPage.jsx
import{LoginForm}from'wasp/client/auth'

exportfunctionLoginPage(){
return(
<LoginForm
// Pass in the socialLayout prop
socialLayout="vertical"
/>
)
}

We get this:

[画像:Vertical social buttons]

Let's Put Everything Together πŸͺ„​

If we provide the logo and custom colors:

  • JavaScript
  • TypeScript
src/appearance.js
exportconst appearance ={
colors:{
brand:'#5969b8',// blue
brandAccent:'#de5998',// pink
submitButtonText:'white',
},
}
src/LoginPage.jsx
import{LoginForm}from'wasp/client/auth'

import{ authAppearance }from'./appearance'
importtodoLogofrom'./todoLogo.png'

exportfunctionLoginPage(){
return<LoginFormappearance={appearance}logo={todoLogo}/>
}

We get a form looking like this:

Custom login form

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /