Skip to main content

LoginForm

<allegro-login-form> is a web component that authenticates readers via a magic login link sent to their email, or via Google and Apple OAuth. On mobile the email input and button stack vertically; on wider screens (≥50em) they sit inline.

Usage

<allegro-login-form></allegro-login-form>

Customise the text labels via HTML attributes:

<allegro-login-form
placeholder-text="Your email"
submit-text="Get my link"
publisher-name="LAist"
continue-text="Keep Reading"
hide-third-party="true"
></allegro-login-form>

Attributes

AttributeTypeDefaultDescription
placeholder-texttextEnter your emailPlaceholder shown inside the email input.
submit-texttextSend Login LinkLabel for the magic-link submit button.
hide-third-partybooleanfalseSet to true to hide the Google and Apple social login buttons.
publisher-nametext(empty)Publisher name shown in the success state, e.g. "Welcome back to LAist!"
continue-texttext(empty)Override the continue button label in the success state.
learn-more-urltext(empty)URL to navigate to when the continue button is clicked in success state.
tracking-datatext(empty)JSON object of custom data merged into every tracked event, e.g. "{'campaign': 'header'}".

States

The component progresses through four states as the magic-link flow advances:

StateTriggerDescription
emailInitial render (unauthenticated, no token in URL)Email input + social login buttons.
loadingInitial render when allegro_token is present in the URLSpinner shown while the SDK validates the token.
successInitial render (already authenticated), or allegro:magic-link:authenticated firesCheckmark + "Welcome back" with a continue button.
link-sentallegro:login-form:magic-link:sent fires"Check your email inbox" with a resend option.
expiredallegro:magic-link:failed fires"Your link has expired" with a send-new-link button.

If the user is already signed in when the component renders, it skips straight to the success state.

Events

Dispatched by this component

NameBubblesDetailDescription
allegro:login-form:magic-link:sentyes{ email: string, data?: Record<string, unknown> }Fired after a magic link is successfully sent. Triggers the link-sent state.
allegro:login-form:authenticatedyes(none)Fired on both auth flows (magic link and social) before the flow-specific event.
allegro:login-form:magic-link:authenticatedyes(none)Fired after a magic link is validated successfully. Follows allegro:login-form:authenticated.
allegro:login-form:third-party:authenticatedyes{ provider: string, session_id: string, token: string }Fired after a successful Google or Apple login. Follows allegro:login-form:authenticated. provider is the provider name (e.g. google).
allegro:login-form:continueyes(none)Fired when the user clicks the continue button in the success state.

Listened to by this component (on window)

NameDetailDescription
allegro:magic-link:authenticated(none)Dispatched by the SDK after a magic link is validated successfully. Transitions to the success state.
allegro:magic-link:failed{ error: string }Dispatched by the SDK when magic link validation fails (e.g. expired token). Transitions to the expired state.

Slots

Slot nameAppears in stateDescription
headeremailRendered above the email input. Use for a title or description. Hidden once the form transitions to another state.
footeremailRendered below the email input (and social buttons when present). Use for supplementary links. Hidden once the form transitions to another state.
after-formemailRendered between the email input and the social login buttons. Use for supplementary inputs such as newsletter opt-in checkboxes. Values from named inputs inside this slot are included in the magic link request data.
successsuccessReplaces the entire success state UI (icon, heading, body, and continue button). When omitted, the default success UI is shown as fallback content.
after-continuesuccessRendered directly below the continue button in the default success UI. Ignored when the success slot is provided.
<allegro-login-form publisher-name="LAist">
<div slot="header">
<h2>Sign in to continue</h2>
<p>Access your account below.</p>
</div>
<p slot="footer">
<a href="/register">Don't have an account? Sign up</a>
</p>
</allegro-login-form>

To override the entire success state:

<allegro-login-form publisher-name="LAist">
<div slot="success">
<h2>You're in!</h2>
<p>Redirecting you now…</p>
</div>
</allegro-login-form>

Tracked Events

The component records the following events via the Allegro SDK.

EventWhenData
magic-link-requestedFired when the user successfully resends a magic link from the link-sent state.(none)

CSS Variables

All visual properties are exposed as CSS custom properties so the component can be themed from the host page without piercing the shadow DOM.

allegro-login-form {
--loginForm--input--background: #fff;
--loginForm--submit--background: #1a1a1a;
}

General

VariableDefaultDescription
--loginForm--colorblackBase text colour for the component.
--loginForm--font-familysystem-ui, sans-serifFont family applied to the entire component.

Input

VariableDefaultDescription
--loginForm--input--background#fffInput background colour.
--loginForm--input--border1px solid #cccInput border shorthand.
--loginForm--input--border-radius0.375remCorner radius applied to the input.
--loginForm--input--font-size1remInput text size.
--loginForm--input--padding0.75rem 1remInput padding shorthand.
--loginForm--input--focus-border-color#555Border colour when the input is focused.

Submit button

VariableDefaultDescription
--loginForm--submit--background#000Button background colour.
--loginForm--submit--color#fffButton text colour.
--loginForm--submit--border-radius0.375remCorner radius applied to the button.
--loginForm--submit--font-size0.875remButton text size.
--loginForm--submit--font-weight700Button font weight.
--loginForm--submit--font-familyinheritButton font family. Inherits the surrounding font by default.
--loginForm--submit--padding0.75rem 1.25remButton padding shorthand.
--loginForm--submit--text-transformuppercaseCSS text-transform applied to button label.

Divider

VariableDefaultDescription
--loginForm--divider--color#333Text and line colour for the "OR" divider.
--loginForm--divider--line-colorcurrentColorOverride only the line colour independently.
--loginForm--divider--margin1rem 0Vertical spacing around the divider.

Social buttons

VariableDefaultDescription
--loginForm--social--background#fffSocial button background colour.
--loginForm--social--hover-background#f9fafbSocial button background on hover.
--loginForm--social--border1px solid #d1d5dbSocial button border shorthand.
--loginForm--social--border-radius0.5remSocial button corner radius.
--loginForm--social--color#111Social button text colour.
--loginForm--social--font-familyinheritSocial button font family. Inherits the surrounding font by default.
--loginForm--social--font-size0.9375remSocial button text size.
--loginForm--social--padding0.7rem 1remSocial button padding shorthand.
--loginForm--social--gap0.75remGap between the two social buttons.

Loading spinner

VariableDefaultDescription
--loginForm--loading--track-colorcurrentColorSpinner colour. Inherits the component text colour by default.
VariableDefaultDescription
--loginForm--state-icon--background#111Background colour of the circular state icon.
--loginForm--state-heading--color#111Heading text colour.
--loginForm--state-heading--font-size1.25remHeading font size.
--loginForm--state-heading--font-weight700Heading font weight.
--loginForm--state-body--color#555Body and disclaimer text colour.
--loginForm--state-body--font-size0.9375remBody text size.
--loginForm--resend--color#555Resend link text colour.
--loginForm--resend--hover-color#111Resend link text colour on hover.
--loginForm--resend--font-size0.875remResend link font size.
--loginForm--resend-error--color#b91c1cText colour for the inline error shown below the resend/send-new-link button.

Error message

VariableDefaultDescription
--loginForm--error--background#fef2f2Error container background colour.
--loginForm--error--border1px solid #fecacaError container border shorthand.
--loginForm--error--accent-color#dc2626Left accent border colour.
--loginForm--error--border-radius0.375remError container corner radius.
--loginForm--error--color#b91c1cError message text colour.
--loginForm--error--icon-colorcurrentColorError icon colour (inherits text colour by default).
--loginForm--error--padding0.625rem 0.875remError container padding.

Example: Dark Background

When placing the component on a dark or coloured background, override the divider and social button colours so they read clearly:

allegro-login-form {
--loginForm--divider--color: rgba(255, 255, 255, 0.7);
--loginForm--social--background: transparent;
--loginForm--social--border: 1px solid rgba(255, 255, 255, 0.4);
--loginForm--social--color: #fff;
--loginForm--social--hover-background: rgba(255, 255, 255, 0.08);
}