@jgb-solutions/kit 0.2.2 → 0.2.3
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/CHANGELOG.md +4 -0
- package/README.md +9 -1
- package/dist/auth/expo.d.ts +6 -0
- package/dist/auth/expo.js +7 -8
- package/dist/auth/rules.d.ts +6 -2
- package/dist/auth/rules.js +2 -2
- package/dist/auth.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@jgb-solutions/kit`. Versions follow semver.
|
|
4
4
|
|
|
5
|
+
## 0.2.3
|
|
6
|
+
|
|
7
|
+
- `createMobileAuth({ randomId })` (`kit/auth/expo`): signing up without an email no longer needs a global `crypto`. React Native's Hermes has none, so `signUp` crashed there ("Property 'crypto' doesn't exist", found in the jgb-starter app template). Pass expo-crypto's `randomUUID`; it defaults to the runtime's `crypto.randomUUID` when present, and without either, `signUp` answers `NO_RANDOM_ID` instead of throwing. `placeholderEmail(randomId?)` takes the same function.
|
|
8
|
+
|
|
5
9
|
## 0.2.2
|
|
6
10
|
|
|
7
11
|
- Connecting Google while signed in (`/link-social`, `linkGoogle`) keeps every session of the account: the owner proved both sides, and signing their other devices out would be a bad surprise. A Google sign-in that joins a confirmed account still ends every session of that account. The hook tells them apart by who is signed in: a browser holding another account's session counts as a join. `afterAccountSaved(account, adapter, signedInUserId)` replaces 0.2.0's `keepSessionToken`, and `AccountAdapter` uses `findSession` instead of `listSessions` and `deleteSessions`.
|
package/README.md
CHANGED
|
@@ -119,11 +119,19 @@ const { withUser, requireUser, requireAdmin } = authMiddleware({
|
|
|
119
119
|
#### `kit/auth/expo`: the mobile app
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
|
+
import { randomUUID } from 'expo-crypto'
|
|
122
123
|
import * as SecureStore from 'expo-secure-store'
|
|
123
124
|
import * as Passkeys from 'react-native-passkeys'
|
|
124
125
|
import { createMobileAuth } from '@jgb-solutions/kit/auth/expo'
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
// randomId: Hermes has no global crypto; sign-up without an email needs one for its placeholder address.
|
|
128
|
+
export const auth = createMobileAuth({
|
|
129
|
+
origin: 'https://app.example.com',
|
|
130
|
+
storage: SecureStore,
|
|
131
|
+
tokenKey: 'example.session',
|
|
132
|
+
fetchMe,
|
|
133
|
+
randomId: randomUUID,
|
|
134
|
+
})
|
|
127
135
|
|
|
128
136
|
const session = useSyncExternalStore(auth.subscribe, auth.getSession)
|
|
129
137
|
await auth.signIn('maria', password) // or an email address
|
package/dist/auth/expo.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export type MobileAuthConfig<U> = {
|
|
|
33
33
|
fetchMe: () => Promise<U>;
|
|
34
34
|
/** Runs after each sign-in (`firstTime`) and each launch with a saved session: syncing what the phone holds. */
|
|
35
35
|
onSignedIn?: (firstTime: boolean) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* A random UUID, for the placeholder address of an account made without an email. Defaults to the
|
|
38
|
+
* runtime's `crypto.randomUUID`, which React Native's Hermes doesn't have: pass expo-crypto's
|
|
39
|
+
* `randomUUID` there. Without either, signUp without an email answers `NO_RANDOM_ID`.
|
|
40
|
+
*/
|
|
41
|
+
randomId?: () => string;
|
|
36
42
|
/** For tests. */
|
|
37
43
|
fetch?: typeof fetch;
|
|
38
44
|
};
|
package/dist/auth/expo.js
CHANGED
|
@@ -14,8 +14,8 @@ var PLACEHOLDER_EMAIL_DOMAIN = "users.invalid";
|
|
|
14
14
|
function isPlaceholderEmail(email) {
|
|
15
15
|
return email.toLowerCase().endsWith(`@${PLACEHOLDER_EMAIL_DOMAIN}`);
|
|
16
16
|
}
|
|
17
|
-
function placeholderEmail() {
|
|
18
|
-
return `${
|
|
17
|
+
function placeholderEmail(randomId = () => globalThis.crypto.randomUUID()) {
|
|
18
|
+
return `${randomId().replaceAll("-", "")}@${PLACEHOLDER_EMAIL_DOMAIN}`;
|
|
19
19
|
}
|
|
20
20
|
function usernameFromName(name, email, fallback) {
|
|
21
21
|
const clean = (text) => (typeof text.normalize === "function" ? text.normalize("NFKD") : text).replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[\s-]+/g, ".").replace(/[^a-z0-9_.]/g, "").replace(/\.{2,}/g, ".").replace(/^[._]+|[._]+$/g, "").slice(0, USERNAME.max - 5).replace(/[._]+$/g, "");
|
|
@@ -172,12 +172,11 @@ function createMobileAuth(config) {
|
|
|
172
172
|
},
|
|
173
173
|
signUp(input) {
|
|
174
174
|
const username = input.username.trim().toLowerCase();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
175
|
+
const randomId = config.randomId ?? (typeof globalThis.crypto?.randomUUID === "function" ? () => globalThis.crypto.randomUUID() : null);
|
|
176
|
+
const email = input.email?.trim() || (randomId ? placeholderEmail(randomId) : null);
|
|
177
|
+
if (!email)
|
|
178
|
+
return Promise.resolve({ ok: false, code: "NO_RANDOM_ID" });
|
|
179
|
+
return signInWith("/sign-up/email", { name: input.name?.trim() || username, username, email, password: input.password });
|
|
181
180
|
},
|
|
182
181
|
signInWithGoogle(idToken, options = {}) {
|
|
183
182
|
return signInWith("/sign-in/social", {
|
package/dist/auth/rules.d.ts
CHANGED
|
@@ -24,8 +24,12 @@ export declare function usernameProblem(username: string): 'too-short' | 'too-lo
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const PLACEHOLDER_EMAIL_DOMAIN = "users.invalid";
|
|
26
26
|
export declare function isPlaceholderEmail(email: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A new placeholder address, random enough never to collide. `randomId` defaults to the runtime's
|
|
29
|
+
* `crypto.randomUUID`; React Native's Hermes has no global `crypto`, so an app there passes its own
|
|
30
|
+
* (expo-crypto's `randomUUID`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function placeholderEmail(randomId?: () => string): string;
|
|
29
33
|
/**
|
|
30
34
|
* A username made from a person's name, for accounts made with Google: "Marie-Ève Dupont" →
|
|
31
35
|
* "marie.eve.dupont". Accents dropped, spaces and dashes to dots, anything else out, short enough to
|
package/dist/auth/rules.js
CHANGED
|
@@ -14,8 +14,8 @@ var PLACEHOLDER_EMAIL_DOMAIN = "users.invalid";
|
|
|
14
14
|
function isPlaceholderEmail(email) {
|
|
15
15
|
return email.toLowerCase().endsWith(`@${PLACEHOLDER_EMAIL_DOMAIN}`);
|
|
16
16
|
}
|
|
17
|
-
function placeholderEmail() {
|
|
18
|
-
return `${
|
|
17
|
+
function placeholderEmail(randomId = () => globalThis.crypto.randomUUID()) {
|
|
18
|
+
return `${randomId().replaceAll("-", "")}@${PLACEHOLDER_EMAIL_DOMAIN}`;
|
|
19
19
|
}
|
|
20
20
|
function usernameFromName(name, email, fallback) {
|
|
21
21
|
const clean = (text) => (typeof text.normalize === "function" ? text.normalize("NFKD") : text).replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[\s-]+/g, ".").replace(/[^a-z0-9_.]/g, "").replace(/\.{2,}/g, ".").replace(/^[._]+|[._]+$/g, "").slice(0, USERNAME.max - 5).replace(/[._]+$/g, "");
|
package/dist/auth.js
CHANGED
|
@@ -21,8 +21,8 @@ var PLACEHOLDER_EMAIL_DOMAIN = "users.invalid";
|
|
|
21
21
|
function isPlaceholderEmail(email) {
|
|
22
22
|
return email.toLowerCase().endsWith(`@${PLACEHOLDER_EMAIL_DOMAIN}`);
|
|
23
23
|
}
|
|
24
|
-
function placeholderEmail() {
|
|
25
|
-
return `${
|
|
24
|
+
function placeholderEmail(randomId = () => globalThis.crypto.randomUUID()) {
|
|
25
|
+
return `${randomId().replaceAll("-", "")}@${PLACEHOLDER_EMAIL_DOMAIN}`;
|
|
26
26
|
}
|
|
27
27
|
function usernameFromName(name, email, fallback) {
|
|
28
28
|
const clean = (text) => (typeof text.normalize === "function" ? text.normalize("NFKD") : text).replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[\s-]+/g, ".").replace(/[^a-z0-9_.]/g, "").replace(/\.{2,}/g, ".").replace(/^[._]+|[._]+$/g, "").slice(0, USERNAME.max - 5).replace(/[._]+$/g, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jgb-solutions/kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Generic plumbing for web apps on Bun and Cloudflare Workers: small, typed, tree-shakable modules (Cloudflare Access, Better Auth).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "JGB Solutions",
|