@molecule/app-auth-shell-solid 0.0.0-stage → 1.1.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/LICENSE +202 -0
- package/README.md +521 -2
- package/dist/AuthFormStateProvider.d.ts +29 -0
- package/dist/AuthFormStateProvider.d.ts.map +1 -0
- package/dist/AuthFormStateProvider.jsx +44 -0
- package/dist/AuthFormStateProvider.jsx.map +1 -0
- package/dist/AuthShell.d.ts +99 -0
- package/dist/AuthShell.d.ts.map +1 -0
- package/dist/AuthShell.jsx +187 -0
- package/dist/AuthShell.jsx.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +153 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/useAuthFormState.d.ts +25 -0
- package/dist/useAuthFormState.d.ts.map +1 -0
- package/dist/useAuthFormState.js +121 -0
- package/dist/useAuthFormState.js.map +1 -0
- package/package.json +68 -4
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuthFormState` (Solid primitive) — cross-view auth form persistence.
|
|
3
|
+
*
|
|
4
|
+
* Holds the email (and any other shared auth fields) so a value typed on one
|
|
5
|
+
* auth view (Login / Signup / ForgotPassword / ResetPassword) is carried over
|
|
6
|
+
* when the user navigates to another. Backed by the `@molecule/app-storage`
|
|
7
|
+
* `StorageProvider` abstraction (never raw `sessionStorage`/`localStorage`).
|
|
8
|
+
*
|
|
9
|
+
* The state is CLEARED on successful auth (call `clear()` from the success
|
|
10
|
+
* handler) so credentials do not linger.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { createEffect, createSignal, onCleanup } from 'solid-js';
|
|
15
|
+
import { getLogger } from '@molecule/app-logger';
|
|
16
|
+
import { createMemoryStorageProvider } from '@molecule/app-storage';
|
|
17
|
+
/** Default storage key for persisted auth form fields. */
|
|
18
|
+
export const DEFAULT_AUTH_FORM_STATE_KEY = 'molecule.auth.form-state';
|
|
19
|
+
/**
|
|
20
|
+
* Process-shared in-memory provider used as the default backing store.
|
|
21
|
+
* Shared (not per-call) so the email survives the unmount/remount of an auth
|
|
22
|
+
* view within one SPA session even without an injected provider.
|
|
23
|
+
*/
|
|
24
|
+
let defaultStorage;
|
|
25
|
+
/**
|
|
26
|
+
* Lazily creates (once) and returns the process-shared in-memory storage
|
|
27
|
+
* provider used as the default backing store.
|
|
28
|
+
*
|
|
29
|
+
* @returns The shared in-memory `StorageProvider`.
|
|
30
|
+
*/
|
|
31
|
+
const getDefaultStorage = () => {
|
|
32
|
+
defaultStorage ??= createMemoryStorageProvider();
|
|
33
|
+
return defaultStorage;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Solid primitive holding email + shared auth fields, persisted across auth
|
|
37
|
+
* views via an injectable `StorageProvider` and cleared on successful auth.
|
|
38
|
+
*
|
|
39
|
+
* @param options - Optional storage provider, storage key, and seed fields.
|
|
40
|
+
* @returns The current fields plus `setField`/`setFields`/`clear` and a `hydrated` flag.
|
|
41
|
+
*/
|
|
42
|
+
export function useAuthFormState(options) {
|
|
43
|
+
const logger = getLogger('auth-form-state');
|
|
44
|
+
const storage = options?.storage ?? getDefaultStorage();
|
|
45
|
+
const storageKey = options?.storageKey ?? DEFAULT_AUTH_FORM_STATE_KEY;
|
|
46
|
+
const [fields, setFieldsSignal] = createSignal({
|
|
47
|
+
...(options?.initialFields ?? {}),
|
|
48
|
+
});
|
|
49
|
+
const [hydrated, setHydrated] = createSignal(false);
|
|
50
|
+
// Mirror the latest fields so setters compute the next value synchronously.
|
|
51
|
+
let current = fields();
|
|
52
|
+
/**
|
|
53
|
+
* Persists the next state, logging (never throwing) on failure.
|
|
54
|
+
*
|
|
55
|
+
* @param next - The next field values.
|
|
56
|
+
*/
|
|
57
|
+
const persist = (next) => {
|
|
58
|
+
storage.set(storageKey, next).catch((error) => {
|
|
59
|
+
logger.warn('Failed to persist auth form state', { error, storageKey });
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
createEffect(() => {
|
|
63
|
+
let cancelled = false;
|
|
64
|
+
void (async () => {
|
|
65
|
+
try {
|
|
66
|
+
const stored = await storage.get(storageKey);
|
|
67
|
+
if (cancelled)
|
|
68
|
+
return;
|
|
69
|
+
if (stored && typeof stored === 'object') {
|
|
70
|
+
// Values the user already typed win over stored.
|
|
71
|
+
const merged = { ...stored, ...current };
|
|
72
|
+
current = merged;
|
|
73
|
+
setFieldsSignal(merged);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
logger.warn('Failed to read persisted auth form state', { error, storageKey });
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (!cancelled)
|
|
81
|
+
setHydrated(true);
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
onCleanup(() => {
|
|
85
|
+
cancelled = true;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Sets a single field and persists the new state.
|
|
90
|
+
*
|
|
91
|
+
* @param name - The field name.
|
|
92
|
+
* @param value - The new value.
|
|
93
|
+
*/
|
|
94
|
+
const setField = (name, value) => {
|
|
95
|
+
const next = { ...current, [name]: value };
|
|
96
|
+
current = next;
|
|
97
|
+
setFieldsSignal(next);
|
|
98
|
+
persist(next);
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Merges a patch of fields and persists the new state.
|
|
102
|
+
*
|
|
103
|
+
* @param patch - The fields to merge.
|
|
104
|
+
*/
|
|
105
|
+
const setFields = (patch) => {
|
|
106
|
+
const next = { ...current, ...patch };
|
|
107
|
+
current = next;
|
|
108
|
+
setFieldsSignal(next);
|
|
109
|
+
persist(next);
|
|
110
|
+
};
|
|
111
|
+
/** Clears all persisted auth form state and removes the storage key. */
|
|
112
|
+
const clear = () => {
|
|
113
|
+
current = {};
|
|
114
|
+
setFieldsSignal({});
|
|
115
|
+
storage.remove(storageKey).catch((error) => {
|
|
116
|
+
logger.warn('Failed to clear persisted auth form state', { error, storageKey });
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
return { fields, hydrated, setField, setFields, clear };
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=useAuthFormState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthFormState.js","sourceRoot":"","sources":["../src/useAuthFormState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,2BAA2B,EAAwB,MAAM,uBAAuB,CAAA;AAIzF,0DAA0D;AAC1D,MAAM,CAAC,MAAM,2BAA2B,GAAG,0BAA0B,CAAA;AAErE;;;;GAIG;AACH,IAAI,cAA2C,CAAA;AAE/C;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,GAAoB,EAAE;IAC9C,cAAc,KAAK,2BAA2B,EAAE,CAAA;IAChD,OAAO,cAAc,CAAA;AACvB,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAiC;IAChE,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,CAAA;IACvD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,2BAA2B,CAAA;IAErE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,YAAY,CAAiB;QAC7D,GAAG,CAAC,OAAO,EAAE,aAAa,IAAI,EAAE,CAAC;KAClC,CAAC,CAAA;IACF,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GA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AM,QAAQ,GAAG,CAAC,IAAY,EAAE,KAAa,EAAQ,EAAE;QACrD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAA;QAC1C,OAAO,GAAG,IAAI,CAAA;QACd,eAAe,CAAC,IAAI,CAAC,CAAA;QACrB,OAAO,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAA;IAED;;;;OAIG;IACH,MAAM,SAAS,GAAG,CAAC,KAAqB,EAAQ,EAAE;QAChD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,CAAA;QACrC,OAAO,GAAG,IAAI,CAAA;QACd,eAAe,CAAC,IAAI,CAAC,CAAA;QACrB,OAAO,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAA;IAED,wEAAwE;IACxE,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,OAAO,GAAG,EAAE,CAAA;QACZ,eAAe,CAAC,EAAE,CAAC,CAAA;QACnB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACzC,MAAM,CAAC,IAAI,CAAC,2CAA2C,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAA;QACjF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-auth-shell-solid",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Auth-page layout shell — centered card with heading/subheading/form/footer + back-link below. Composable children for per-app decorative background + brand mark.",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-auth-shell-solid",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"auth",
|
|
28
|
+
"shell",
|
|
29
|
+
"layout",
|
|
30
|
+
"solid"
|
|
31
|
+
],
|
|
32
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
37
|
+
"directory": "packages/app/features/auth-shell-solid"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20"
|
|
41
|
+
},
|
|
42
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@molecule/app-logger": "^1.0.1",
|
|
48
|
+
"@molecule/app-solid": "^3.6.0",
|
|
49
|
+
"@molecule/app-storage": "^1.0.1",
|
|
50
|
+
"@molecule/app-ui": "^1.3.11",
|
|
51
|
+
"@molecule/app-ui-solid": "^1.1.0",
|
|
52
|
+
"solid-js": "^1.8.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
56
|
+
"@molecule/app-i18n": "1.2.2",
|
|
57
|
+
"@molecule/app-icons": "1.0.4",
|
|
58
|
+
"@molecule/app-logger": "1.1.0",
|
|
59
|
+
"@molecule/app-solid": "3.7.2",
|
|
60
|
+
"@molecule/app-storage": "1.1.1",
|
|
61
|
+
"@molecule/app-ui": "1.4.0",
|
|
62
|
+
"@molecule/app-ui-solid": "1.1.5",
|
|
63
|
+
"@types/node": "26.6.5",
|
|
64
|
+
"jsdom": "30.1.3",
|
|
65
|
+
"solid-js": "1.9.17",
|
|
66
|
+
"typescript": "6.0.3",
|
|
67
|
+
"vite-plugin-solid": "2.11.15",
|
|
68
|
+
"vitest": "4.1.12"
|
|
69
|
+
}
|
|
70
|
+
}
|