The sign-in button
Your sign-in button already has a look. Keep it. The orangecheck button takes
your button's class and draws nothing of its own: it brings the orangecheck
mark, the words, the popup and the busy state. Install @orangecheck/me-client
0.47.0 or later; what changed says what each version added.
In three different sitesLink to this section
Three made-up sites, each with its own buttons. Beside each site's own button is the orangecheck button, given the same class, then the mark alone in the site's icon button. Switch the docs between light and dark to see both. Signing in here opens the real orangecheck window.
ReactLink to this section
import type { ReactElement } from 'react';
import { SignInWithOrangecheck } from '@orangecheck/me-client/react';
import '@orangecheck/me-client/button.css';
declare function keepSession(token: string): Promise<void>;
export function SignIn(): ReactElement {
return (
<SignInWithOrangecheck
className="btn btn-outline"
onSignedIn={({ token }) => keepSession(token)}
/>
);
}
keepSession posts the token to your server, which verifies it with
withOcAuth and keeps it in an httpOnly cookie. Import button.css
once; it is optional and has zero specificity, so every rule of yours wins over
it. Without it the button is yours with the mark in it.
| Prop | Type | Default | |
|---|---|---|---|
onSignedIn | ( | required | Called with { account, token }. The button stays busy until it settles. |
onOutcome | ( | none | Called with how every window ended, an object with a status. See when it doesn't sign in. |
appearance | 'inherit' | 'brand' | inherit | inherit adds no colour, font, border, radius or focus ring. brand is orangecheck's button. |
mark | 'mono' | 'brand' | 'tile' | false | mono | false for none. See the mark. |
label | string | false | "Sign in with orangecheck" | The words, in your language if you like, keeping "orangecheck". false draws the mark alone. See the words. |
busyLabel | string | "Signing in…" | What it says while the window is open. |
accessibleLabel | string | "Sign in with orangecheck" | What a screen reader says for the mark alone. |
popup | { popupOrigin? | none | Popup options, such as a preview popupOrigin. |
enhanceSignInButton(button, options) takes the same options
(EnhanceSignInButtonOptions). The types come with the package:
import type {
OcPopupOutcome,
OcPopupResult,
} from '@orangecheck/me-client/button';
// OcPopupResult is { account, token }: account.did_oc names the person, and
// the token goes to your server, which verifies it.
export function didOf(result: OcPopupResult): string | undefined {
return result.account.did_oc;
}
// OcPopupOutcome is one of { status: 'signed_in', account, token },
// { status: 'blocked' }, { status: 'closed' }, { status: 'aborted' } or
// { status: 'failed' }.
export function signedIn(outcome: OcPopupOutcome): boolean {
return outcome.status === 'signed_in';
}
Everything else (className, style, id, aria-describedby, disabled)
goes to the native <button>.
Plain HTML and JavaScriptLink to this section
No framework, no bundler. Write the button as you write every other one, and add
data-oc-sign-in, with an empty <span data-oc-mark> where the mark goes:
<button class="cta ghost" data-oc-sign-in>
<span data-oc-mark></span>Sign in with orangecheck
</button>
<p id="oc-note" role="status"></p>
button.css gives the empty span the mark's size, so the button is its final
width before the script runs, and drawing the mark moves nothing. Words already
in the button are kept if they say "orangecheck". For the mark alone, leave the
words out and add data-label="none":
<button class="icon-button" data-oc-sign-in data-label="none">
<span data-oc-mark></span>
</button>
Then enhance it:
import {
enhanceSignInButton,
OUTCOME_COPY,
} from '@orangecheck/me-client/button';
const button = /** @type {HTMLButtonElement} */ (
document.querySelector('[data-oc-sign-in]')
);
const note = /** @type {HTMLElement} */ (document.querySelector('#oc-note'));
enhanceSignInButton(button, {
onSignedIn: async ({ token }) => {
const r = await fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token }),
});
if (r.ok) location.assign('/dashboard');
},
onOutcome: (outcome) => {
if (
outcome.status === 'blocked' ||
outcome.status === 'closed' ||
outcome.status === 'failed'
) {
note.textContent = OUTCOME_COPY[outcome.status];
}
},
});
Under a strict Content-Security-Policy (script-src 'self'), copy
node_modules/@orangecheck/me-client/dist/button.mjs and dist/button.css onto
your own origin and import them from there. button.mjs has no imports, and it
builds the mark node by node, so it needs no innerHTML and works with Trusted
Types. Load it before the click: a window opened after an await is blocked.
enhanceSignInButton returns a function that puts the button back as it was.
From a CDNLink to this section
To load it from jsDelivr, pin the exact version and let the browser check every
byte with Subresource Integrity, so a changed file is refused rather than run on
your page. Integrity covers a <script src>, not an import in an inline
script, so load button-auto.mjs: it enhances every [data-oc-sign-in] button
itself and reports through events, and your own script imports nothing.
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@orangecheck/me-client@0.56.0/dist/button.css"
integrity="sha384-gfzUacSwvkf2ls9b6CLLW8yMUz1VNIrCvGFLsyknbCc2X0i9Ey63C+y13T6VeSTx"
crossorigin="anonymous"
/>
<button class="cta ghost" data-oc-sign-in>
<span data-oc-mark></span>Sign in with orangecheck
</button>
<p id="oc-note" role="status"></p>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@orangecheck/me-client@0.56.0/dist/button-auto.mjs"
integrity="sha384-QEMf5dgzjvvZoCVleBAhCW076aAWZJbm0vUXS7ZD40HIhGEMQgIyVZeUujMA1cS4"
crossorigin="anonymous"
></script>
<script>
document.addEventListener('oc-signed-in', (event) => {
const { token, waitUntil } = event.detail;
waitUntil(
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token }),
}).then((r) => {
if (r.ok) location.assign('/dashboard');
})
);
});
document.addEventListener('oc-sign-in-outcome', (event) => {
document.getElementById('oc-note').textContent = event.detail.message;
});
</script>
| Event | detail |
|---|---|
oc- | account, token, and waitUntil(: the button stays busy until it settles. |
oc- | status, and message: the words to show near the button (empty when there are none). |
Both events are dispatched on the button and bubble, so event.target says
which button it was. Any script on your page can fire them too, and a
CustomEvent is never trusted: never trust account from the event in the
browser. Send only the token to your server, and let its check
(withOcAuth or checkOcToken) be the only answer.
The button carries its options: data-mark (mono, brand, tile, none),
data-appearance (inherit, brand), data-busy-label,
data-accessible-label and data-label="none". It takes no popup address, on
purpose: any script on your page could set one and point your button at a
look-alike sign-in. To test against a stand-in popup, use button.mjs and pass
popup: { popupOrigin, popupPath } from your own code, as the
examples' offline mode does.
The hashes above are for the files of the me-client version the snippet pins, as
npm publishes them. A new version has new hashes: your project's HTML snippet on
ochk.app always shows the current pair. Under a strict Content-Security-Policy,
copy dist/button-auto.mjs and dist/button.css onto your own origin instead.
orangecheck's own buttonLink to this section
If you would rather not style it, appearance="brand" is orangecheck's button:
ink, with the mark as drawn. Theme it with custom properties.
| Property | Default |
|---|---|
- | # |
- | # |
- | # |
- | # |
- | 10px |
- | your font |
- | 1rem |
- | 600 |
- | 1. |
- | # |
Both appearances read these:
| Property | Default | |
|---|---|---|
- | 0. | The space between the mark and the words. |
- | 1. | The mark's width; its height is half that. The tile is 1. square. |
- | 44px | The smallest height, and the mark alone's smallest width. 44px is the rule. Lower it only if your own buttons already give a 44px target some other way. |
While it worksLink to this section
- Clicking opens the orangecheck window inside the click, before anything is awaited, so browsers do not block it.
- While the window is open the button says "Signing in…" (or your
busyLabel), and hasaria-busy="true"andaria-disabled="true". It keeps focus, keeps its width so nothing beside it moves, and opens no second window. - Its accessible name follows the words it shows, so a screen reader hears
"Signing in…" while the window is open, as everyone else reads it. In a test
or a script, find the button by
[data-oc-sign-in], never by its name: the name changes while it works. - When the window closes, the button is ready again, and
onOutcomesays why. See when it doesn't sign in. - A button you set
disablednever opens a window.
When it doesn't sign inLink to this section
onOutcome gets an object, and its status says how the window ended. For
three of them, OUTCOME_COPY has the words to show near the button:
status | When | What to tell the person (OUTCOME_) |
|---|---|---|
signed_ | The person signed in. onSignedIn runs next. | Nothing. |
blocked | The browser refused to open the window, usually a pop-up blocker. | blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again." |
closed | The person closed the window before finishing. Their choice, not an error. | closed: "The sign-in window closed before you finished." |
failed | The window ended without a usable answer: it reported a sign-in with no account or token. | failed: "Sign-in didn't finish. Try again." |
aborted | Your own code cancelled the wait, which the button never does. | Nothing. |
import type { OcPopupOutcome } from '@orangecheck/me-client/button';
import { OUTCOME_COPY } from '@orangecheck/me-client/button';
// The words to show near the button, or '' when there is nothing to say.
export function noteFor(outcome: OcPopupOutcome): string {
if (
outcome.status === 'blocked' ||
outcome.status === 'closed' ||
outcome.status === 'failed'
) {
return OUTCOME_COPY[outcome.status];
}
return '';
}
The tag-loaded button reports the same through its oc-sign-in-outcome event,
whose detail is { status, message }, with these words already in message.
For everyoneLink to this section
- Inside a button with words, the mark is decoration:
aria-hidden, never focused. The words name the button. - The mark alone is named by
aria-label, "Sign in with orangecheck" or youraccessibleLabel, and is at least 44px each way. inheritdraws no focus ring of its own, so your site's ring shows, as on your other buttons. If your buttons have no visible focus style, give them one.brandhas its own ring.- When the system forces its own colours (Windows contrast themes), the mark
becomes one flat shape in the button's text colour, the tile loses its ink
square, and
brand's edge and ring take the system colours. - The words stay on one line, and the mark has its size before it is drawn.
The markLink to this section
The orangecheck mark is an isometric check. It ships with no dependencies in
@orangecheck/mark (opens in a new tab), and
inside the button.
| Variant | Use it |
|---|---|
mono | Anywhere your button's text has 3:1 contrast with its background. It is drawn in your text colour: its three faces at full, 60% and 30% strength. |
brand | On dark backgrounds only. Its lightest face is about 1.3:1 on white. |
tile | On any background: the brand mark on its own ink tile. |
import { markSvg } from '@orangecheck/mark';
declare const slot: HTMLElement;
slot.insertAdjacentHTML('afterbegin', markSvg({ variant: 'mono' }));
Native apps and gamesLink to this section
@orangecheck/mark/assets/ has every variant as SVG and as PNG at 16, 24, 32,
40, 48, 64, 80, 96, 128 and 256 px wide (orangecheck-mark-mono-white-40.png,
and so on). The mark is twice as wide as it is tall, so the 40px file is 20px
tall, the size beside 16px words, and the 80px file is the same mark for a 2x
screen. mono-white reads on a dark theme, mono-black on a light one, and
tile on either. In Godot 4:
var button := Button.new()
button.text = "Sign in with orangecheck"
button.icon = preload("res://ui/orangecheck-mark-mono-white-80.png")
button.add_theme_constant_override("icon_max_width", 40)
button.custom_minimum_size.y = 44
The words are plain text. Keep your theme's font, colours and focus style.
In a web export, the page that hosts the game opens the orangecheck window, as in plain HTML. A native build signs the player in through their own browser: see apps and games.
Download them from npm, or straight from jsDelivr (opens in a new tab).
VersionsLink to this section
Each row is what that version added to the button. The full history is me-client's CHANGELOG (opens in a new tab).
| Version | What changed |
|---|---|
| 0.46.0 | The button: / (enhanceSignInButton), / (SignInWithOrangecheck) and button.. |
| 0.47.0 | Words in any language that keep "orangecheck"; busyLabel; the mark alone (label: false); the [data- placeholder; the width held while busy; inherit drops its own focus ring, so your site's ring shows. |
| 0.48.0 | button-: a <script src> that enhances every button[data- and reports through oc- and oc- events. |
The rulesLink to this section
The wordsLink to this section
| Use | Words |
|---|---|
| Default | Sign in with orangecheck |
| A flow that continues an account | Continue with orangecheck |
| A sign-up form | Sign up with orangecheck |
| While the window is open | Signing in… |
These are the defaults (SIGN_IN_LABELS). In another language, write your own,
and keep the name as it is: "orangecheck", lowercase, a word of its own.
For an action other than signing in, these words are approved too. Use them only when the button does exactly that.
| Action | Words |
|---|---|
| Connect an account on your site to an orangecheck account | Link orangecheck |
| Remove that connection | Unlink orangecheck |
| Confirm a sensitive action by signing in again | Sign in with orangecheck to action |
For example, "Sign in with orangecheck to delete" on the button that confirms deleting an account.
import type { ReactElement } from 'react';
import { SignInWithOrangecheck } from '@orangecheck/me-client/react';
declare function keepSession(token: string): Promise<void>;
export function Connexion(): ReactElement {
return (
<SignInWithOrangecheck
className="btn"
label="Se connecter avec orangecheck"
busyLabel="Connexion…"
onSignedIn={({ token }) => keepSession(token)}
/>
);
}
The button refuses words without "orangecheck" in them, and "OC" or "OrangeCheck" in its place.
Size and spaceLink to this section
- The mark is at least 16px wide. At the default size it is 1.75em, so 16px text gives a 28px mark, 14px tall.
- Leave clear space around the mark of at least a quarter of its width. The default gap to the words is 0.5em.
- Keep the button at least 44px tall.
NeverLink to this section
- Recolour the mark other than mono in your text colour, or put the brand mark on a light background.
- Stretch it, rotate it, split its faces, crop it or outline it.
- Show it larger than your own brand. It says the sign-in goes through orangecheck; it does not stand for your site.
The code and files are MIT. The mark is orangecheck's trademark, and the trademark policy (opens in a new tab) says how it may be used. Using it in a sign-in button, as above, is fine.