@molecule/app-auth-ui-angular
Feature · auth · App (browser) · v1.2.3 · Apache-2.0
Angular auth OAuth button row — config-driven providers + callback exchange (OAuthButtons)
npm install @molecule/app-auth-ui-angularHow it works
@molecule/app-auth-ui-angular is a ready-made auth feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { Component } from '@angular/core'
import { OAuthButtons } from '@molecule/app-auth-ui-angular'
import { oauthConfig } from './config'
// On the Login/Signup page (the OAuth redirect must land back here):
@Component({
selector: 'app-login-page',
standalone: true,
imports: [OAuthButtons],
template: `
<div
mol-auth-oauth-buttons
[oauthConfig]="config"
[showLabels]="true"
(success)="navigate('/dashboard')"
></div>
`,
})
export class LoginPage {
config = oauthConfig
navigate(to: string): void {}
}Works with: @molecule/app-angular, @molecule/app-oauth-buttons-angular, @molecule/app-ui
Reference
Angular auth-kit components — the counterpart of
@molecule/app-auth-ui-react (the same runtime export names, the same
props, and the same rendered DOM for the same input).
Exports the OAuthButtons component — the config-driven OAuth row for
branded Login/Signup pages: reads providers from useOAuth(oauthConfig),
renders the "or continue with" divider + provider buttons, and owns
the CALLBACK half of the page-based flow (?code&state exchange on
the page it is mounted on, with a visible inline error on failure).
NOT the same component as OAuthButtons from
@molecule/app-oauth-buttons-angular — that lower-level primitive takes
an explicit providers list and renders only the row; this one wraps
it and takes the app's oauthConfig from config.ts. Structural
pieces only — branded layout, copy, and chrome stay at the app level.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { OAuthButtons } from '@molecule/app-auth-ui-angular'
import { oauthConfig } from './config'
// On the Login/Signup page (the OAuth redirect must land back here):
@Component({
selector: 'app-login-page',
standalone: true,
imports: [OAuthButtons],
template: `
<div
mol-auth-oauth-buttons
[oauthConfig]="config"
[showLabels]="true"
(success)="navigate('/dashboard')"
></div>
`,
})
export class LoginPage {
config = oauthConfig
navigate(to: string): void {}
}
Type
feature
Installation
npm install @molecule/app-auth-ui-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-oauth-buttons-angular @molecule/app-ui
API
Interfaces
OAuthButtonsProps
Props for the OAuthButtons component, the same as
@molecule/app-auth-ui-react's. In a template, the value props are inputs
([oauthConfig], [showLabels], …), and onSuccess / onError are the
(success) and (error) outputs.
interface OAuthButtonsProps {
/** The app's OAuth config (`oauthConfig` in its `config.ts`), passed to `useOAuth()`. */
oauthConfig: UseOAuthConfig
/** Extra class applied to the outer wrapper. */
className?: string
/** Icon size in pixels. Defaults to 30. */
iconSize?: number
/** Logo color mode — `'brand'` (default, official multi-color) or `'mono'`. */
iconMode?: 'brand' | 'mono'
/** When true, render the provider label text next to the logo. */
showLabels?: boolean
/** Override the default "or continue with" divider text's i18n key. */
dividerKey?: string
/** Override the default "or continue with" divider text. */
dividerDefault?: string
/**
* Called after a successful OAuth login (the session is already
* established), e.g. `() => navigate('/dashboard')`. The `(success)` output.
*/
onSuccess?: () => void
/**
* Called when the OAuth callback exchange fails, with the inline error
* message that is already visible. The `(error)` output.
*/
onError?: (error: string) => void
}
Classes
OAuthButtons
Config-driven OAuth provider button row rendered beneath a login/signup form.
This is the convenience layer over the primitives in
@molecule/app-oauth-buttons-angular: it reads providers +
redirect from useOAuth(oauthConfig), then composes OAuthDivider
(the "or continue with" rule) above OAuthButtons (the button row).
Apps with an oauthConfig object use this; apps that already hold a
raw provider list use the lower-level row directly.
The component also owns the CALLBACK half of the page-based flow:
useOAuth detects ?code&state on the page this row is mounted on,
exchanges the code, and reports the outcome here — a failed exchange
(forged/expired code, state mismatch, provider rejection) renders a
VISIBLE inline error (data-mol-id="oauth-error", role="alert")
instead of failing silently, and a success fires the success output
so the host can navigate into the app.
@Component({
selector: 'div[mol-auth-oauth-buttons]',
standalone: true,
imports: [OAuthButtonRow, OAuthDivider],
inputs: [
'oauthConfig',
'className',
'iconSize',
'iconMode',
'showLabels',
'dividerKey',
'dividerDefault',
],
host: {
// One column with no gap of its own: the divider's own margin is the gap between it and the
// error or the button row, the same distance in a browser and in a native column.
'[class]': 'cm().cn(cm().stack(0), className)',
},
template: `<div mol-oauth-divider [labelKey]="dividerKey" [labelDefault]="dividerDefault"></div>
@if (errorMessage(); as message) {
<!-- No margin on the error: in the column the divider's margin below already set the gap. -->
<div [class]="cm().textError" role="alert" data-mol-id="oauth-error">{{ message }}</div>
}
<div
mol-oauth-buttons
[providers]="oauthProviders()"
[onSelect]="rowOnSelect"
[iconSize]="iconSize"
[iconMode]="iconMode"
[showLabels]="showLabels"
(success)="handleRowSuccess()"
></div>`,
})
export class OAuthButtons {
/** The current `oauthConfig` input, as a signal the hook follows. */
private readonly config = signal<UseOAuthConfig | undefined>(undefined)
/**
* The app's OAuth config, passed to the binding's `useOAuth()`. A changed
* config reaches the hook on this mount (React re-renders the row with it).
* @param value - The config.
*/
set oauthConfig(value: UseOAuthConfig | undefined) {
this.config.set(value)
}
/**
* The app's OAuth config.
* @returns The current config.
*/
get oauthConfig(): UseOAuthConfig | undefined {
return this.config()
}
/** Extra class applied to the outer wrapper. */
className?: string
/** Icon size in pixels (default 30). */
iconSize?: number
/** Logo color mode — `'brand'` (default, official multi-color) or `'mono'`. */
iconMode?: 'brand' | 'mono'
/** When true, render the provider label text next to the logo. */
showLabels?: boolean
/** Override the default "or continue with" divider text's i18n key. */
dividerKey?: string
/** Override the default "or continue with" divider text. */
dividerDefault?: string
/**
* Called after a successful OAuth login (the session is already
* established) — e.g. `() => navigate('/dashboard')`.
*/
@Output() readonly success = new EventEmitter<void>()
/**
* Called when the OAuth callback exchange fails. The (already visible)
* inline error message is passed through for hosts that also want to
* surface it elsewhere.
*/
@Output() readonly error = new EventEmitter<string>()
/** The visible exchange failure, when the callback exchange failed. */
private readonly errorMessage = signal<string | null>(null)
/**
* This component's own injector, captured in the injection context so the
* `useOAuth` call below can run in it once the inputs exist (an Angular
* component reads its inputs after construction, unlike React's
* per-render hook call). It must be the component's injector, not the
* environment's: the hook's `DestroyRef` then ends with this component, so
* an exchange that settles after unmount calls neither output.
*/
private readonly injector = inject(Injector)
/** The `useOAuth` result: providers, redirect and the callback flow. */
private oauth?: ReturnType<typeof useOAuth>
constructor() {
// Leaves no element in the page while there are no providers (React renders null).
useHostPresence(() => this.oauthProviders().length > 0)
}
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* The provider list from `useOAuth(oauthConfig)`.
* @returns The provider ids.
*/
oauthProviders(): string[] {
return this.oauth?.providers ?? []
}
/**
* Leaves the page for the provider (React passes the hook's `redirect`
* directly; a stable wrapper keeps the row's input identity).
* @param provider - The provider id.
*/
readonly rowOnSelect = (provider: string): void => {
this.oauth?.redirect(provider)
}
/**
* React's wrapped row success: clear any visible error, then report
* success to the host.
*/
handleRowSuccess(): void {
this.errorMessage.set(null)
this.success.emit()
}
/**
* Starts the OAuth hook once the inputs exist. `useOAuth` needs an
* injection context, which `ngOnInit` is not, so the captured component
* injector provides one; the auth client it reads resolves up to the
* app-level one (`provideAuth`), exactly what React's hook reads from
* its provider.
*/
ngOnInit(): void {
this.oauth = runInInjectionContext(this.injector, () =>
useOAuth(
computed(() => ({
...this.config(),
onSuccess: () => {
this.errorMessage.set(null)
this.success.emit()
},
onError: (message: string) => {
// The message is the api's (localized) error body or the hook's
// fallback — render it so a failed callback is never invisible.
this.errorMessage.set(message)
this.error.emit(message)
},
})),
),
)
}
}
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.12.0 || ^4.0.0@molecule/app-oauth-buttons-angular^1.0.0@molecule/app-ui^1.0.1
Runtime Dependencies
@angular/common@angular/core@angular/platform-browser@molecule/app-angular@molecule/app-oauth-buttons-angular@molecule/app-ui
Renders nothing when oauthConfig yields no providers (the host is
detached from the DOM) — safe to include unconditionally. Mount it on
the page the OAuth provider redirects back to, or the code exchange
never runs. A failed exchange renders an inline role="alert" error
(data-mol-id="oauth-error") and also fires the error output.
Divider copy defaults to "or continue with" (override via
dividerKey / dividerDefault); translations come from the
companion @molecule/app-locales-oauth-buttons locale bond.