Skip to content

Component Reference

All components are exported from @mindfulauth/astro/components:

import {
MAuthPublic,
MAuthProtected,
MAuthForm,
MAuthEmailInput,
MAuthPasswordInput,
MAuthNameInput,
MAuthSubmitButton,
MAuthMessage,
MAuthTurnstile,
MAuthTwoFACodeInput,
MAuthTwoFASection,
MAuthPasswordChangePending,
MAuthChangePassword,
MAuthEnable2FA,
MAuthDisable2FA,
MAuthAddAuthMethod,
} from '@mindfulauth/astro/components';

Layout components wrap entire pages. They inject the necessary auth scripts and set up the page structure.

Wraps public (unauthenticated) pages such as login, register, and forgot-password.

Pages using this layout:

  • Login
  • Register
  • Forgot Password
  • Magic Link Login
  • Magic Link Register
  • Reset Password
  • Email Verification
  • Resend Verification
PropTypeRequiredDefaultDescription
scriptsScriptName[]YesAuth scripts to include (see Auth Scripts)
---
import { MAuthPublic } from '@mindfulauth/astro/components';
import MyLayout from '../layouts/MyLayout.astro';
---
<MyLayout title="Login">
<MAuthPublic scripts={['LoginScript']}>
<!-- page content -->
</MAuthPublic>
</MyLayout>

Wraps protected (authenticated) pages. The middleware enforces authentication before the page renders.

PropTypeRequiredDefaultDescription
scriptsScriptName[]NoAuth scripts to include (see Auth Scripts)
---
import { MAuthProtected } from '@mindfulauth/astro/components';
import MyLayout from '../layouts/MyLayout.astro';
---
<MyLayout title="Dashboard">
<MAuthProtected scripts={['SecurityScript']}>
<!-- page content -->
</MAuthProtected>
</MyLayout>

Form components are used inside MAuthPublic or MAuthProtected pages to build authentication forms.

The container for any Mindful Auth form. Identifies the form to auth scripts via formName.

PropTypeRequiredDefaultDescription
formNamestringYesUnique identifier used by auth scripts to bind to this form
classstringNoCSS class(es) on the <form> element

The formName value must match what the corresponding auth script expects. Using an incorrect value will silently break the form:

formNameRequired script
"login"LoginScript
"register"RegisterPasswordScript
"forgot-password"ForgotPasswordScript
"magic-login"MagicLoginScript
"magic-register"MagicRegisterScript
"resend-verification"ResendVerificationScript
"reset-password"ResetPasswordScript
<MAuthForm formName="login" class="auth-form">
<!-- form fields -->
</MAuthForm>

An email address input field.

PropTypeRequiredDefaultDescription
labelstringNo"Email"Label text
placeholderstringNoInput placeholder
classstringNoCSS class(es) on the wrapper element
<MAuthEmailInput label="Email" placeholder="you@example.com" class="my-input" />

A password input field. Use fieldName to distinguish between different password fields on the same form.

PropTypeRequiredDefaultDescription
labelstringYesLabel text
fieldName'password' | 'confirm-password' | 'new-password'YesSets the data-mindfulauth-field attribute used by auth scripts
classstringNoCSS class(es) on the wrapper element
<MAuthPasswordInput label="Password" fieldName="password" />
<MAuthPasswordInput label="Confirm Password" fieldName="confirm-password" />

A name input field for registration forms.

PropTypeRequiredDefaultDescription
labelstringNo"Name"Label text
classstringNoCSS class(es) on the wrapper element
<MAuthNameInput label="Full Name" class="my-input" />

The form submit button.

PropTypeRequiredDefaultDescription
labelstringYesButton text
classstringNoCSS class(es) on the <button> element
<MAuthSubmitButton label="Log In" class="btn-primary" />

A message/status area where auth scripts display success or error feedback.

PropTypeRequiredDefaultDescription
defaultTextstringNo""Initial text shown before any auth action
classstringNoCSS class(es) on the message element
<MAuthMessage defaultText="Please log in to continue." class="auth-message" />

Renders a Cloudflare Turnstile CAPTCHA widget. The widget is automatically initialized by TurnstileInit (included in layout scripts).

PropTypeRequiredDefaultDescription
theme'light' | 'dark' | 'auto'No'light'Widget color theme
size'flexible' | 'normal' | 'compact'No'flexible'Widget size
languagestringNo'auto'Widget language code
appearance'always' | 'execute' | 'interaction-only'No'always'When to show the widget
classstringNoCSS class(es) on the wrapper element
<MAuthTurnstile theme="dark" size="compact" language="en" appearance="always" class="my-turnstile" />

An input field for 2FA verification codes. Used on login and 2FA setup pages.

PropTypeRequiredDefaultDescription
namestringYesInput name attribute
labelstringNo"2FA Code"Label text
classstringNoCSS class(es) on the wrapper element
<MAuthTwoFACodeInput name="totp-code" label="Authentication Code" class="my-input" />

A conditional section that is shown only when 2FA verification is required during login. Auth scripts toggle its visibility automatically.

PropTypeRequiredDefaultDescription
classstringNoCSS class(es) on the section element
<MAuthTwoFASection class="twofa-section">
<MAuthTwoFACodeInput name="totp-code" label="2FA Code" />
</MAuthTwoFASection>

A notice displayed when a password change is required before the user can proceed. Auth scripts toggle its visibility automatically.

PropTypeRequiredDefaultDescription
classstringNoCSS class(es) on the element
<MAuthPasswordChangePending class="pending-notice" />

These components are used on account security pages (typically [memberid]/index.astro). They include their own forms and are controlled by SecurityScript.

A self-contained change-password form.

PropTypeRequiredDefaultDescription
classstringNoCSS class on the section wrapper
formClassstringNoCSS class on the inner <form>
buttonClassstringNoCSS class on the submit button
titlestringNo"Change Password"Section heading
submitLabelstringNo"Update Password"Submit button text
<MAuthChangePassword
class="section"
formClass="form"
buttonClass="btn"
title="Change Password"
submitLabel="Update Password"
/>

A self-contained 2FA setup flow including QR code display, verification, and recovery codes.

PropTypeRequiredDefaultDescription
classstringNoCSS class on the section wrapper
setupClassstringNoCSS class on the setup container
formClassstringNoCSS class on the verification form
qrWrapperClassstringNoCSS class on the QR code outer wrapper
qrDisplayClassstringNoCSS class on the QR code display area
buttonClassstringNoCSS class on action buttons
recoveryCodesClassstringNoCSS class on the recovery codes container
recoveryListClassstringNoCSS class on the recovery codes list
recoveryCodesTitlestringNo"Save Your Recovery Codes"Recovery codes section heading
copyLabelstringNo"Copy Codes"Copy button text
titlestringNo"Two-Factor Authentication"Section heading
setupTitlestringNo"Scan the QR Code"QR code step heading
enableLabelstringNo"Enable 2FA"Button to start the 2FA setup flow
verifyLabelstringNo"Verify & Enable"Submit button for the verification step
<MAuthEnable2FA
class="section"
setupClass="setup"
formClass="form"
qrWrapperClass="qr-wrapper"
qrDisplayClass="qr-display"
buttonClass="btn"
recoveryCodesClass="recovery"
recoveryListClass="recovery-list"
recoveryCodesTitle="Save Your Recovery Codes"
copyLabel="Copy Codes"
title="Two-Factor Authentication"
setupTitle="Scan the QR Code"
enableLabel="Enable 2FA"
verifyLabel="Verify & Enable"
/>

A self-contained form to disable 2FA on the account.

PropTypeRequiredDefaultDescription
classstringNoCSS class on the section wrapper
formClassstringNoCSS class on the <form>
buttonClassstringNoCSS class on the submit button
titlestringNo"Disable Two-Factor Authentication"Section heading
submitLabelstringNo"Disable 2FA"Submit button text
<MAuthDisable2FA
class="section"
formClass="form"
buttonClass="btn"
title="Disable Two-Factor Authentication"
submitLabel="Disable 2FA"
/>

A button to add a new authentication method (e.g., adding a password to a magic-link-only account).

PropTypeRequiredDefaultDescription
classstringNoCSS class on the section wrapper
buttonClassstringNoCSS class on the button
titlestringNo"Add Authentication Method"Section heading
submitLabelstringNo"Add Authentication Method"Button text
<MAuthAddAuthMethod
class="section"
buttonClass="btn"
title="Add Authentication Method"
submitLabel="Add Authentication Method"
/>

Auth scripts are the client-side JavaScript that power authentication flows. You specify which scripts to load per page via the scripts prop on MAuthPublic or MAuthProtected.

Script NameDescription
MainScriptCore script — always included automatically. Handles frame-busting, fetch wrapper, 2FA cache, cookie checks, and logout.
TurnstileInitAutomatically included if you use MAuthTurnstile on the page. Fetches the tenant site key and renders the Turnstile widget.
LoginScriptHandles password login with 2FA support.
RegisterPasswordScriptHandles password-based registration.
ForgotPasswordScriptHandles the forgot-password form submission.
MagicLoginScriptHandles magic link login form submission.
MagicRegisterScriptHandles magic link registration form submission.
ResendVerificationScriptHandles the resend-verification-email form.
ResetPasswordScriptHandles password reset (requires token + optional 2FA).
VerifyEmailScriptAuto-runs on page load to complete email verification.
VerifyMagicLinkScriptHandles magic link verification with Turnstile and optional 2FA.
SecurityScriptPowers the security settings page — change password, enable/disable 2FA, add auth method.

For complete page examples covering every authentication flow, see the Page Examples guide.