Sign in
A sign-in screen for lit-material: password, a code by mail, creating an account and resetting a password, with single sign-on buttons.
- 12.0 KB gzipped
- @lit-material/sign-in 1.8.0
- Renders on the server
Example
Sign in
A sign-in screen: email and password, a code by mail, creating an account and resetting a password, with room for single sign-on buttons. It only collects input. Your handler calls the server and sets busy, error, notice or awaiting-code from the answer.
Try it
Any password signs in except wrong. Codes are "mailed" at once.
Sign in
Two steps for mailed codes
Signing in with a code, confirming a new account and resetting a password first submit the address. Send the mail, then set awaiting-code: the screen asks for the code (and the new password when resetting). A pasted or suggested code submits by itself.
signIn.addEventListener("lit-material-sign-in", async ({ detail }) => {
signIn.busy = true;
signIn.error = "";
try {
if (detail.method === "code" && !detail.code) {
await api.mailCode(detail.email);
signIn.awaitingCode = true;
} else {
await api.signIn(detail);
location.assign("/");
}
} catch (error) {
signIn.error = error.message;
} finally {
signIn.busy = false;
}
});
Install
npm install @lit-material/sign-in @lit-material/tokens
import "@lit-material/sign-in";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-sign-in>
A sign-in screen: email and password, a code sent by mail, creating an
account and resetting a forgotten password, with room for "Continue with
Google" style buttons. It only collects input: listen for
lit-material-sign-in, call your server, then set busy, error,
notice or awaiting-code from the answer.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
mode | mode | SignInMode | "sign-in" | Which flow is showing. |
method | method | SignInMethod | "password" | How to sign in, in mode="sign-in". |
methods | methods | string | "password" | What the server offers, space-separated: password, code (a sign-in code by mail), sign-up, forgot.
Links to the other views appear only for these. |
email | email | string | "" | The address, kept across views. Set it to prefill. |
awaitingCode | awaiting-code | boolean | false | The code is mailed: ask for it (and the new password when resetting). |
busy | busy | boolean | false | A request is running: the form is off and the button says so. |
error | error | string | "" | The server's refusal, shown above the form. |
notice | notice | string | "" | A note shown above the form, e.g. "Password changed. Sign in with the new one." |
heading | heading | string | "" | Overrides the heading of the current view. |
codeLength | code-length | number | 6 | Characters in the mailed code. |
passwordMinlength | password-minlength | number | 8 | Shortest password accepted when creating one. |
Events
| Event | Description |
|---|---|
lit-material-sign-in-view-change | The reader switched view; detail is { mode, method }. |
lit-material-sign-in | The form was submitted; detail is SignInDetail. |
Slots
| Slot | Description |
|---|---|
logo | Above the heading. |
providers | Single sign-on buttons, shown above the form with an "or" divider. |
footer | Under everything: terms, the server in use, help links. |
CSS parts
| Part | Description |
|---|---|
card | The outer box. |
form | The form. |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-sign-in-width | Width of the card (default 400px, never wider than its container). |