@dbx-tools/ui-auth 0.6.93 → 0.6.94
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 +7 -1
- package/package.json +5 -5
- package/src/react/auth-client.ts +18 -0
- package/src/react/auth-gate.tsx +2 -7
- package/src/react/index.ts +1 -0
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Key features:
|
|
|
8
8
|
- automatic conditional passkey mediation on supported browsers;
|
|
9
9
|
- first-login passkey enrollment prompt;
|
|
10
10
|
- authenticated passkey list, rename, add, and remove controls;
|
|
11
|
+
- status and logout helpers for tunnel-aware application controls;
|
|
11
12
|
- HttpOnly Better Auth sessions with no browser token storage;
|
|
12
13
|
- AppKit and dbx-tools branding primitives.
|
|
13
14
|
|
|
@@ -27,6 +28,11 @@ root.render(
|
|
|
27
28
|
);
|
|
28
29
|
```
|
|
29
30
|
|
|
31
|
+
`getAuthStatus()` reports whether the current request is behind the tunnel gate.
|
|
32
|
+
`logout()` clears the session and navigates to the server-configured login
|
|
33
|
+
destination.
|
|
34
|
+
|
|
30
35
|
## Public subpaths
|
|
31
36
|
|
|
32
|
-
- `@dbx-tools/ui-auth/react` - `AuthGate`
|
|
37
|
+
- `@dbx-tools/ui-auth/react` - `AuthGate`, `PasskeyManager`, `getAuthStatus`,
|
|
38
|
+
and `logout`.
|
package/package.json
CHANGED
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@better-auth/passkey": "^1.6.25",
|
|
28
|
-
"@dbx-tools/shared-auth": "0.6.
|
|
29
|
-
"@dbx-tools/shared-core": "0.6.
|
|
30
|
-
"@dbx-tools/ui-appkit": "0.6.
|
|
31
|
-
"@dbx-tools/ui-branding": "0.6.
|
|
28
|
+
"@dbx-tools/shared-auth": "0.6.94",
|
|
29
|
+
"@dbx-tools/shared-core": "0.6.94",
|
|
30
|
+
"@dbx-tools/ui-appkit": "0.6.94",
|
|
31
|
+
"@dbx-tools/ui-branding": "0.6.94",
|
|
32
32
|
"better-auth": "^1.6.25",
|
|
33
33
|
"react": "^19.2.4",
|
|
34
34
|
"react-dom": "^19.2.4"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"version": "0.6.
|
|
40
|
+
"version": "0.6.94",
|
|
41
41
|
"type": "module",
|
|
42
42
|
"exports": {
|
|
43
43
|
"./react": "./src/react/index.ts",
|
package/src/react/auth-client.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { passkeyClient } from "@better-auth/passkey/client";
|
|
2
|
+
import { authLogoutResultSchema, authStatusSchema, type AuthStatus } from "@dbx-tools/shared-auth";
|
|
2
3
|
import { createAuthClient } from "better-auth/client";
|
|
3
4
|
import { emailOTPClient } from "better-auth/client/plugins";
|
|
4
5
|
|
|
@@ -19,6 +20,23 @@ export interface PasskeySummary {
|
|
|
19
20
|
deviceType?: string | null;
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export async function getAuthStatus(): Promise<AuthStatus> {
|
|
24
|
+
const response = await fetch(`${AUTH_BASE}/status`, { credentials: "include" });
|
|
25
|
+
if (!response.ok) throw new Error(`Auth status failed with ${response.status}`);
|
|
26
|
+
return authStatusSchema.parse(await response.json());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function logout(): Promise<boolean> {
|
|
30
|
+
const response = await fetch(`${AUTH_BASE}/logout`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
credentials: "include",
|
|
33
|
+
});
|
|
34
|
+
const parsed = authLogoutResultSchema.safeParse(await response.json());
|
|
35
|
+
if (!response.ok || !parsed.success || !parsed.data.ok) return false;
|
|
36
|
+
if (typeof window !== "undefined") window.location.assign(parsed.data.redirectTo);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
export async function requestEmailOtp(email: string): Promise<boolean> {
|
|
23
41
|
const result = await client.emailOtp.sendVerificationOtp({ email, type: "sign-in" });
|
|
24
42
|
return result.error === null;
|
package/src/react/auth-gate.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AuthStatus } from "@dbx-tools/shared-auth";
|
|
2
1
|
import { net } from "@dbx-tools/shared-core";
|
|
3
2
|
import { Button, Input } from "@dbx-tools/ui-appkit/react";
|
|
4
3
|
import { BrandIcon, useBrand } from "@dbx-tools/ui-branding/react";
|
|
@@ -6,7 +5,7 @@ import { type FormEvent, type ReactNode, useCallback, useEffect, useState } from
|
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
7
|
addPasskey,
|
|
9
|
-
|
|
8
|
+
getAuthStatus,
|
|
10
9
|
requestEmailOtp,
|
|
11
10
|
signInPasskey,
|
|
12
11
|
verifyEmailOtp,
|
|
@@ -32,11 +31,7 @@ export function AuthGate({ children, title, description }: AuthGateProps): React
|
|
|
32
31
|
|
|
33
32
|
useEffect(() => {
|
|
34
33
|
let cancelled = false;
|
|
35
|
-
void
|
|
36
|
-
.then(async (response) => {
|
|
37
|
-
if (!response.ok) throw new Error(`Authentication status failed (${response.status})`);
|
|
38
|
-
return (await response.json()) as AuthStatus;
|
|
39
|
-
})
|
|
34
|
+
void getAuthStatus()
|
|
40
35
|
.then((status) => {
|
|
41
36
|
if (cancelled) return;
|
|
42
37
|
setPasskeysEnabled(status.passkeysEnabled === true);
|
package/src/react/index.ts
CHANGED