@edgespark/web 0.0.1-beta.4 → 0.0.1-beta.6
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 +14 -4
- package/dist/auth/create-auth.d.ts +3 -2
- package/dist/auth/types.d.ts +15 -20
- package/dist/auth-ui/ManagedAuthUI.d.ts +1 -0
- package/dist/client.d.ts +6 -5
- package/dist/index.cjs +63 -63
- package/dist/index.es.js +734 -484
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -47,12 +47,13 @@ es.authUI.mount(container, { redirectTo: "/dashboard" });
|
|
|
47
47
|
|
|
48
48
|
### `auth`
|
|
49
49
|
|
|
50
|
-
`es.auth`
|
|
50
|
+
`es.auth` keeps better-auth's API shape and adds two EdgeSpark helpers:
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
53
|
const session = await es.auth.requireSession();
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
|
|
55
|
+
const unsubscribe = es.auth.onSessionChange((nextSession) => {
|
|
56
|
+
console.log(nextSession?.user.email ?? "signed out");
|
|
56
57
|
});
|
|
57
58
|
```
|
|
58
59
|
|
|
@@ -60,7 +61,12 @@ const unsubscribe = es.auth.onSessionChange((session) => {
|
|
|
60
61
|
session lookup itself fails, it preserves the upstream auth error code/status
|
|
61
62
|
so route guards can distinguish backend failures from a real sign-out.
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
`onSessionChange()` is hydration-safe: it waits for the first session lookup to
|
|
65
|
+
complete before emitting, so apps do not mistake initial loading for a real
|
|
66
|
+
signed-out state. Successful sign-in/sign-up/sign-out mutations also prompt
|
|
67
|
+
other tabs to refetch their session state.
|
|
68
|
+
|
|
69
|
+
Use the familiar auth methods directly:
|
|
64
70
|
|
|
65
71
|
```ts
|
|
66
72
|
await es.auth.signIn.email({ email, password });
|
|
@@ -134,6 +140,10 @@ Password reset has one special rule:
|
|
|
134
140
|
- in controlled mode, `onSuccess({ action: "password-reset" })` fires and the caller owns the next step
|
|
135
141
|
- in redirect mode, the UI returns to sign-in with a success notice instead of redirecting to an authenticated page
|
|
136
142
|
|
|
143
|
+
In controlled mode, `authUI` stops mutating the container after `onSuccess`
|
|
144
|
+
runs. If the app wants to close, replace, or reuse that container, it owns that
|
|
145
|
+
teardown explicitly.
|
|
146
|
+
|
|
137
147
|
## Flows covered by the managed UI
|
|
138
148
|
|
|
139
149
|
- email/password sign-in
|
|
@@ -4,8 +4,9 @@ export declare function syncEdgeSparkAuthSession(authClient: BetterAuthClientIns
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates the headless auth module.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* knowledge
|
|
7
|
+
* The exposed API intentionally keeps better-auth's shape so existing upstream
|
|
8
|
+
* knowledge transfers directly. EdgeSpark adds session helpers and sync
|
|
9
|
+
* semantics on top of that familiar surface.
|
|
9
10
|
*/
|
|
10
11
|
export declare function createEdgeSparkAuth(): EdgeSparkAuth;
|
|
11
12
|
/**
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -17,11 +17,8 @@ export interface AuthEndpointResult<TData = unknown> {
|
|
|
17
17
|
error?: AuthEndpointError | null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* EdgeSpark keeps auth
|
|
21
|
-
*
|
|
22
|
-
* All better-auth client methods work directly. EdgeSpark adds three
|
|
23
|
-
* small conveniences on top: `requireSession`, `onSessionChange`, and
|
|
24
|
-
* a wrapped `signOut` that best-effort invalidates the same-tab session.
|
|
20
|
+
* EdgeSpark keeps the auth API shape aligned with better-auth while adding a
|
|
21
|
+
* small set of session helpers on top.
|
|
25
22
|
*/
|
|
26
23
|
export type EdgeSparkAuth = BetterAuthClientInstance & {
|
|
27
24
|
/**
|
|
@@ -35,30 +32,28 @@ export type EdgeSparkAuth = BetterAuthClientInstance & {
|
|
|
35
32
|
*/
|
|
36
33
|
requireSession(): Promise<AuthSession>;
|
|
37
34
|
/**
|
|
38
|
-
* Subscribes to session changes for the current
|
|
35
|
+
* Subscribes to session changes for the current browser context.
|
|
39
36
|
*
|
|
40
37
|
* The first emission is hydration-safe: it waits for the initial server
|
|
41
|
-
* session
|
|
42
|
-
* premature `null`
|
|
43
|
-
* session is still being verified.
|
|
38
|
+
* session lookup to complete before firing, so subscribers never receive a
|
|
39
|
+
* premature `null` while a cookie session is still settling.
|
|
44
40
|
*
|
|
45
|
-
* After
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
41
|
+
* After hydration, successful session atom updates are forwarded immediately.
|
|
42
|
+
* Successful auth mutations that create or clear a session in the current
|
|
43
|
+
* tab also prompt other tabs to refetch their session state, so logout and
|
|
44
|
+
* same-tab sign-in/sign-up converge quickly across tabs.
|
|
45
|
+
*
|
|
46
|
+
* Transient lookup failures that temporarily clear the atom to `null` are
|
|
47
|
+
* ignored so subscribers do not mistake a backend error for a real sign-out.
|
|
49
48
|
*
|
|
50
49
|
* Returns an unsubscribe function.
|
|
51
50
|
*/
|
|
52
51
|
onSessionChange(callback: SessionChangeCallback): () => void;
|
|
53
52
|
/**
|
|
54
|
-
* Signs out and
|
|
55
|
-
*
|
|
56
|
-
* This wraps better-auth's `signOut` and additionally forces the session
|
|
57
|
-
* atom to refetch after a successful sign-out so `onSessionChange`
|
|
58
|
-
* subscribers update in the same tab.
|
|
53
|
+
* Signs out and then best-effort synchronizes session state for the current
|
|
54
|
+
* tab and other open tabs.
|
|
59
55
|
*
|
|
60
|
-
* The
|
|
61
|
-
* sign-out result is still returned unchanged.
|
|
56
|
+
* The underlying better-auth result is returned unchanged.
|
|
62
57
|
*/
|
|
63
58
|
signOut(...args: Parameters<BetterAuthClientInstance["signOut"]>): ReturnType<BetterAuthClientInstance["signOut"]>;
|
|
64
59
|
};
|
|
@@ -30,6 +30,7 @@ export declare class ManagedAuthUI implements MountedAuthUI {
|
|
|
30
30
|
constructor(container: HTMLElement, auth: BetterAuthClientInstance, options: MountAuthUIOptions, loadConfig: () => Promise<NormalizedAuthUIConfig>, runtimeOptions?: ManagedAuthUIRuntimeOptions | undefined);
|
|
31
31
|
destroy(): void;
|
|
32
32
|
private initialize;
|
|
33
|
+
private redirectAfterManagedReturnLookupFailure;
|
|
33
34
|
private readMountSession;
|
|
34
35
|
private render;
|
|
35
36
|
private renderLoading;
|
package/dist/client.d.ts
CHANGED
|
@@ -3,14 +3,15 @@ import { EdgeSparkAuth } from './auth/types';
|
|
|
3
3
|
import { EdgeSparkAuthUI } from './auth-ui';
|
|
4
4
|
export interface EdgeSparkClient {
|
|
5
5
|
/**
|
|
6
|
-
* Headless auth
|
|
6
|
+
* Headless auth client with a better-auth-aligned API shape, plus a small
|
|
7
|
+
* set of EdgeSpark session helpers:
|
|
7
8
|
*
|
|
8
9
|
* - `requireSession()` — resolves or throws, for route guards
|
|
9
|
-
* - `onSessionChange(
|
|
10
|
-
* - `signOut()` — signs out and best-effort invalidates the same-tab session atom
|
|
10
|
+
* - `onSessionChange()` — hydration-safe session observer
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
12
|
+
* Standard auth methods such as `signIn.email`, `signIn.social`,
|
|
13
|
+
* `signUp.email`, `signOut`, and `getSession` remain available on the same
|
|
14
|
+
* familiar shape.
|
|
14
15
|
*/
|
|
15
16
|
auth: EdgeSparkAuth;
|
|
16
17
|
/**
|