@sneekin/ui 0.4.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -19
- package/dist/component.d.ts +5 -5
- package/dist/country-picker.d.ts +1 -1
- package/dist/fetch-handlers.d.ts +10 -9
- package/dist/index.d.ts +6 -6
- package/dist/index.js +148 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -149
- package/dist/index.mjs.map +1 -1
- package/dist/state.d.ts +34 -21
- package/dist/theme.d.ts +2 -2
- package/dist/use-sneek-login.d.ts +44 -0
- package/package.json +1 -1
- package/dist/use-sneek-otp.d.ts +0 -40
package/README.md
CHANGED
|
@@ -18,12 +18,12 @@ React 17 or newer, as a peer dependency.
|
|
|
18
18
|
## Use it
|
|
19
19
|
|
|
20
20
|
```tsx
|
|
21
|
-
import {
|
|
21
|
+
import { SneekLogin, createFetchHandlers } from '@sneekin/ui';
|
|
22
22
|
|
|
23
23
|
export function Login() {
|
|
24
24
|
return (
|
|
25
|
-
<
|
|
26
|
-
{...createFetchHandlers(
|
|
25
|
+
<SneekLogin
|
|
26
|
+
{...createFetchHandlers()}
|
|
27
27
|
onSuccess={(session) => router.push('/app')}
|
|
28
28
|
/>
|
|
29
29
|
);
|
|
@@ -34,23 +34,41 @@ export function Login() {
|
|
|
34
34
|
|
|
35
35
|
| Route | Body | Returns |
|
|
36
36
|
| --- | --- | --- |
|
|
37
|
-
| `POST
|
|
38
|
-
| `POST
|
|
37
|
+
| `POST /api/auth/request` | `{ identifier }` | `{ requestId, channel?, maskedIdentifier?, expiresAt? }` |
|
|
38
|
+
| `POST /api/auth/verify` | `{ requestId, code }` | whatever your session payload is |
|
|
39
|
+
|
|
40
|
+
Point them elsewhere with `createFetchHandlers({ requestUrl, verifyUrl })`.
|
|
39
41
|
|
|
40
42
|
Your server holds the Sneek API key and calls Sneek. The browser never sees it.
|
|
41
43
|
|
|
44
|
+
## You never pick the channel
|
|
45
|
+
|
|
46
|
+
Ask Sneek to verify a person; **Sneek decides how**. The channel comes from the
|
|
47
|
+
`authChannels` bitmask on your application — SMS, WhatsApp, email, and push and
|
|
48
|
+
QR-scan as they land — and can change without a front-end release.
|
|
49
|
+
|
|
50
|
+
`channel` and `maskedIdentifier` come back on the request response for **display
|
|
51
|
+
only**. The card uses them to say what actually happened:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
Sent via WhatsApp to +91***29
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If your backend does not forward them, the card falls back to `Sent to <what the
|
|
58
|
+
visitor typed>` and nothing else changes. Neither field is ever an input.
|
|
59
|
+
|
|
42
60
|
## Theming
|
|
43
61
|
|
|
44
62
|
It follows the system colour scheme out of the box. Pin it if you prefer:
|
|
45
63
|
|
|
46
64
|
```tsx
|
|
47
|
-
<
|
|
65
|
+
<SneekLogin theme="dark" {...handlers} />
|
|
48
66
|
```
|
|
49
67
|
|
|
50
68
|
Override the single accent colour — everything else derives from it:
|
|
51
69
|
|
|
52
70
|
```tsx
|
|
53
|
-
<
|
|
71
|
+
<SneekLogin accentColor="#7c3aed" {...handlers} />
|
|
54
72
|
```
|
|
55
73
|
|
|
56
74
|
The code entry step shows the destination with an inline way to change it,
|
|
@@ -66,13 +84,13 @@ itself if the visitor pastes a full international number (anything
|
|
|
66
84
|
starting with `+`):
|
|
67
85
|
|
|
68
86
|
```tsx
|
|
69
|
-
<
|
|
87
|
+
<SneekLogin defaultCountry="GB" {...handlers} />
|
|
70
88
|
```
|
|
71
89
|
|
|
72
90
|
Lock the field to just one identifier — no chip, no toggle:
|
|
73
91
|
|
|
74
92
|
```tsx
|
|
75
|
-
<
|
|
93
|
+
<SneekLogin identifierMode="email" {...handlers} />
|
|
76
94
|
```
|
|
77
95
|
|
|
78
96
|
`identifierMode` is `'both' | 'phone' | 'email'`, default `'both'`.
|
|
@@ -80,7 +98,7 @@ Lock the field to just one identifier — no chip, no toggle:
|
|
|
80
98
|
Swap the mark, drop the sub-heading, or remove the Sneek line:
|
|
81
99
|
|
|
82
100
|
```tsx
|
|
83
|
-
<
|
|
101
|
+
<SneekLogin
|
|
84
102
|
logo={<MyLogo />}
|
|
85
103
|
subtitle={null}
|
|
86
104
|
showBranding={false}
|
|
@@ -89,18 +107,20 @@ Swap the mark, drop the sub-heading, or remove the Sneek line:
|
|
|
89
107
|
```
|
|
90
108
|
|
|
91
109
|
For anything further, `className` and `style` land on the outer card, and every
|
|
92
|
-
control carries a stable class (`.sneek-
|
|
93
|
-
`.sneek-
|
|
110
|
+
control carries a stable class (`.sneek-login-input`, `.sneek-login-button`,
|
|
111
|
+
`.sneek-login-link`) you can target.
|
|
94
112
|
|
|
95
113
|
## Props
|
|
96
114
|
|
|
97
115
|
| Prop | Type | Default |
|
|
98
116
|
| --- | --- | --- |
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
117
|
+
| `requestVerification` | `(identifier) => Promise<VerificationRequest>` | — (required) |
|
|
118
|
+
| `verify` | `({ requestId, code }) => Promise<TResult>` | — (required) |
|
|
101
119
|
| `onSuccess` | `(result: TResult) => void` | — |
|
|
120
|
+
| `onError` | `(error: unknown) => void` | — |
|
|
102
121
|
| `title` | `string` | `'Sign in'` |
|
|
103
|
-
| `
|
|
122
|
+
| `verifyTitle` | `string` | `'Enter the code'` |
|
|
123
|
+
| `subtitle` | `ReactNode \| null` | `'Enter your email or phone to continue.'` |
|
|
104
124
|
| `identifierMode` | `'both' \| 'phone' \| 'email'` | `'both'` |
|
|
105
125
|
| `defaultCountry` | ISO 3166-1 alpha-2, e.g. `'GB'` | `'IN'` (India) |
|
|
106
126
|
| `identifierLabel` | `string` | `'Mobile number'` / `'Email address'`, per mode |
|
|
@@ -117,13 +137,17 @@ If the card does not suit you, use the hook and render whatever you like. It
|
|
|
117
137
|
holds the whole state machine — step, busy flags, errors, resend:
|
|
118
138
|
|
|
119
139
|
```tsx
|
|
120
|
-
import {
|
|
140
|
+
import { useSneekLogin, createFetchHandlers } from '@sneekin/ui';
|
|
121
141
|
|
|
122
|
-
const
|
|
123
|
-
//
|
|
124
|
-
//
|
|
142
|
+
const login = useSneekLogin(createFetchHandlers());
|
|
143
|
+
// login.step, login.identifier, login.code, login.error,
|
|
144
|
+
// login.channel, login.maskedIdentifier,
|
|
145
|
+
// login.startVerification(), login.submitCode(), login.resend(), login.back()
|
|
125
146
|
```
|
|
126
147
|
|
|
148
|
+
`channelLabel(login.channel)` turns the raw channel into something readable
|
|
149
|
+
(`whatsapp` → `WhatsApp`) if you write your own status line.
|
|
150
|
+
|
|
127
151
|
## License
|
|
128
152
|
|
|
129
153
|
UNLICENSED — © Abblor Tech Pvt Ltd.
|
package/dist/component.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SneekLoginHandlers } from './use-sneek-login.js';
|
|
3
3
|
export type SneekTheme = 'auto' | 'light' | 'dark';
|
|
4
4
|
export type SneekIdentifierMode = 'phone' | 'email' | 'both';
|
|
5
|
-
export interface
|
|
5
|
+
export interface SneekLoginProps<TResult = unknown> extends SneekLoginHandlers<TResult> {
|
|
6
6
|
/** Heading above the form. @default 'Sign in' */
|
|
7
7
|
title?: string;
|
|
8
8
|
/** Heading once the code has been sent. @default 'Enter the code' */
|
|
@@ -55,10 +55,10 @@ export interface SneekOtpLoginProps<TResult = unknown> extends SneekOtpHandlers<
|
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
57
57
|
* ```tsx
|
|
58
|
-
* <
|
|
59
|
-
* {...createFetchHandlers(
|
|
58
|
+
* <SneekLogin
|
|
59
|
+
* {...createFetchHandlers()}
|
|
60
60
|
* onSuccess={(session) => router.push('/app')}
|
|
61
61
|
* />
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
export declare function
|
|
64
|
+
export declare function SneekLogin<TResult = unknown>(props: SneekLoginProps<TResult>): ReactNode;
|
package/dist/country-picker.d.ts
CHANGED
package/dist/fetch-handlers.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VerificationRequest } from './state.js';
|
|
2
2
|
export interface FetchHandlerOptions {
|
|
3
3
|
/**
|
|
4
|
-
* Partner backend endpoint that
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Partner backend endpoint that starts a verification. Receives
|
|
5
|
+
* `{ identifier }`, must return
|
|
6
|
+
* `{ requestId, channel?, maskedIdentifier?, expiresAt? }`.
|
|
7
|
+
* @default '/api/auth/request'
|
|
7
8
|
*/
|
|
8
9
|
requestUrl?: string;
|
|
9
10
|
/**
|
|
10
|
-
* Partner backend endpoint that
|
|
11
|
+
* Partner backend endpoint that completes a verification. Receives
|
|
11
12
|
* `{ requestId, code }`, returns whatever your app needs (session, token…).
|
|
12
|
-
* @default '/api/auth/verify
|
|
13
|
+
* @default '/api/auth/verify'
|
|
13
14
|
*/
|
|
14
15
|
verifyUrl?: string;
|
|
15
16
|
/** Extra headers (e.g. CSRF token) to send on both requests. */
|
|
@@ -18,12 +19,12 @@ export interface FetchHandlerOptions {
|
|
|
18
19
|
credentials?: RequestCredentials;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
* Build {@link
|
|
22
|
+
* Build {@link SneekLoginHandlers} that POST to your own backend endpoints.
|
|
22
23
|
* Those endpoints call the Sneek API server-side with your secret key.
|
|
23
24
|
*/
|
|
24
25
|
export declare function createFetchHandlers<TResult = unknown>(options?: FetchHandlerOptions): {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
requestVerification: (identifier: string) => Promise<VerificationRequest>;
|
|
27
|
+
verify: (input: {
|
|
27
28
|
requestId: string;
|
|
28
29
|
code: string;
|
|
29
30
|
}) => Promise<TResult>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { SNEEK_ACCENT_DARK, SNEEK_ACCENT_LIGHT, } from './theme';
|
|
4
|
-
export { COUNTRIES, DEFAULT_COUNTRY_ISO2, flagEmoji, countryByIso2, countryByDialPrefix, detectCountryFromLocale, type Country, } from './countries';
|
|
5
|
-
export { createFetchHandlers, type FetchHandlerOptions, } from './fetch-handlers';
|
|
6
|
-
export {
|
|
1
|
+
export { useSneekLogin, type SneekLoginHandlers, type UseSneekLogin, } from './use-sneek-login.js';
|
|
2
|
+
export { SneekLogin, type SneekLoginProps, type SneekTheme, type SneekIdentifierMode, } from './component.js';
|
|
3
|
+
export { SNEEK_ACCENT_DARK, SNEEK_ACCENT_LIGHT, } from './theme.js';
|
|
4
|
+
export { COUNTRIES, DEFAULT_COUNTRY_ISO2, flagEmoji, countryByIso2, countryByDialPrefix, detectCountryFromLocale, type Country, } from './countries.js';
|
|
5
|
+
export { createFetchHandlers, type FetchHandlerOptions, } from './fetch-handlers.js';
|
|
6
|
+
export { loginReducer, initialLoginState, channelLabel, type SneekChannel, type SneekLoginStep, type SneekLoginStatus, type SneekLoginState, type SneekLoginAction, type VerificationRequest, } from './state.js';
|