Auth

Ready to use authentication forms.

Theming

The Auth component is a multipart component. The styling needs to be applied to each part specifically.

To learn more about styling multipart components, visit the Chakra UI Component Style page.

Anatomy

  • container
  • inner
  • main

Theming utilities

  • createMultiStyleConfigHelpers: a function that returns a set of utilities for creating style configs for a multipart component (definePartsStyle and defineMultiStyleConfig).
  • definePartsStyle: a function used to create multipart style objects.
  • defineMultiStyleConfig: a function used to define the style configuration for a multipart component.
import { authAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(authAnatomy.keys)

Customizing the default theme

import { authAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(authAnatomy.keys)
const baseStyle = definePartsStyle({
// define the part you're going to style
container: {
bg: 'red.200', // change the backgroundColor of the container
},
})
export const authTheme = defineMultiStyleConfig({ baseStyle })

After customizing the app shell theme, we can import it in our theme file and add it in the components property:

import { extendTheme } from '@chakra-ui/react'
import { authAnatomy } from './components/auth'
export const theme = extendTheme({
components: { SuiAuth: authAnatomy },
})

Saas UI components are prefixed with Sui to avoid conflicts with Chakra UI. This is a crucial step to make sure that any changes that we make to the app shell theme are applied.

Adding a custom size

Let's assume we want to include an extra large app shell icon size. Here's how we can do that:

import { authAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(authAnatomy.keys)
const xl = definePartsStyle({
container: {
height: '1000px'
}
})
const sizes = {
xl,
}
export const app shellTheme = defineMultiStyleConfig({ sizes })
// Now we can use the new `xl` size
<Auth size="xl"> ... </Auth>

Every time you're adding anything new to the theme, you'd need to run the CLI command to get proper autocomplete in your IDE. You can learn more about the CLI tool here.

Adding a custom variant

Let's assume we want to include a custom pill variant. Here's how we can do that:

import { authAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(authAnatomy.keys)
const custom = definePartsStyle({
container: {
border: '1px solid',
borderColor: 'gray.200',
background: 'gray.50',
borderRadius: 'full',
// Let's also provide dark mode alternatives
_dark: {
borderColor: 'gray.600',
background: 'gray.800',
},
},
main: {
border: '1px solid',
borderColor: 'gray.200',
background: 'gray.200',
color: 'gray.500',
_dark: {
borderColor: 'gray.600',
background: 'gray.600',
color: 'gray.400',
},
},
})
export const authTheme = defineMultiStyleConfig({
variants: { custom },
})
// Now we can use the new `custom` variant
<Auth variant="custom"> ... </Auth>

Changing the default properties

Let's assume we want to change the default size and variant of every app shell in our app. Here's how we can do that:

import { authAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { defineMultiStyleConfig } = createMultiStyleConfigHelpers(
authAnatomy.keys,
)
export const authTheme = defineMultiStyleConfig({
defaultProps: {
variant: 'custom',
},
})
// This saves you time, instead of manually setting the size and
// variant every time you use an app shell:
<Auth variant="custom"> ... </Auth>

Was this helpful?