@howone/sdk 0.1.23 → 0.1.25
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/dist/index.d.mts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +45 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -201,7 +201,7 @@ var AUTH_ROOT_VALUE, DEFAULT_PROJECT_ID, AUTH_ROOT, config_default;
|
|
|
201
201
|
var init_config = __esm({
|
|
202
202
|
"src/config.ts"() {
|
|
203
203
|
"use strict";
|
|
204
|
-
AUTH_ROOT_VALUE = "https://howone
|
|
204
|
+
AUTH_ROOT_VALUE = "https://howone.dev";
|
|
205
205
|
DEFAULT_PROJECT_ID = null;
|
|
206
206
|
AUTH_ROOT = getAuthRoot();
|
|
207
207
|
try {
|
|
@@ -1569,33 +1569,70 @@ function GlobalToastContainer() {
|
|
|
1569
1569
|
// src/components/auth/HowoneProvider.tsx
|
|
1570
1570
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1571
1571
|
var HowoneContext = createContext2(null);
|
|
1572
|
-
var
|
|
1572
|
+
var HowOneProvider = ({
|
|
1573
1573
|
children,
|
|
1574
1574
|
showFloatingButton = true,
|
|
1575
|
+
projectId,
|
|
1575
1576
|
defaultTheme = "system",
|
|
1576
1577
|
themeStorageKey = "howone-theme",
|
|
1577
|
-
forceDefaultTheme = false
|
|
1578
|
+
forceDefaultTheme = false,
|
|
1579
|
+
authUrl = "https://howone.dev/auth",
|
|
1580
|
+
redirectOnUnauthenticated = true
|
|
1578
1581
|
}) => {
|
|
1579
1582
|
const [user, setUser] = useState4(() => parseUserFromToken(getToken()));
|
|
1580
1583
|
const [token, setTokenState] = useState4(() => getToken());
|
|
1584
|
+
const [hasCheckedUrlToken, setHasCheckedUrlToken] = useState4(false);
|
|
1581
1585
|
useEffect4(() => {
|
|
1582
1586
|
try {
|
|
1583
1587
|
const params = new URLSearchParams(window.location.search);
|
|
1584
|
-
|
|
1588
|
+
let urlToken = params.get("access_token") || params.get("token");
|
|
1589
|
+
if (!urlToken && window.location.hash) {
|
|
1590
|
+
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
1591
|
+
urlToken = hashParams.get("access_token") || hashParams.get("token");
|
|
1592
|
+
}
|
|
1585
1593
|
if (urlToken) {
|
|
1594
|
+
console.log("[HowOneProvider] Token captured from URL, storing to localStorage...");
|
|
1586
1595
|
setToken(urlToken);
|
|
1587
1596
|
setTokenState(urlToken);
|
|
1588
1597
|
setUser(parseUserFromToken(urlToken));
|
|
1589
1598
|
params.delete("access_token");
|
|
1590
1599
|
params.delete("token");
|
|
1600
|
+
params.delete("project_id");
|
|
1591
1601
|
const newSearch = params.toString();
|
|
1592
|
-
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "")
|
|
1602
|
+
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
|
|
1593
1603
|
window.history.replaceState({}, "", newUrl);
|
|
1604
|
+
console.log("[HowOneProvider] Token stored successfully, URL cleaned");
|
|
1594
1605
|
}
|
|
1595
1606
|
} catch (e) {
|
|
1596
|
-
console.error("[
|
|
1607
|
+
console.error("[HowOneProvider] Failed to capture token from URL:", e);
|
|
1608
|
+
} finally {
|
|
1609
|
+
setHasCheckedUrlToken(true);
|
|
1597
1610
|
}
|
|
1598
1611
|
}, []);
|
|
1612
|
+
useEffect4(() => {
|
|
1613
|
+
if (!hasCheckedUrlToken) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
if (redirectOnUnauthenticated && !token && !user) {
|
|
1617
|
+
const currentUrl = new URL(window.location.href);
|
|
1618
|
+
if (!currentUrl.pathname.includes("/auth")) {
|
|
1619
|
+
console.log("[HowOneProvider] No token found, redirecting to auth page...");
|
|
1620
|
+
try {
|
|
1621
|
+
const authUrlObj = new URL(authUrl);
|
|
1622
|
+
const redirectUri = window.location.href;
|
|
1623
|
+
authUrlObj.searchParams.set("redirect_uri", redirectUri);
|
|
1624
|
+
if (projectId) {
|
|
1625
|
+
authUrlObj.searchParams.set("project_id", projectId);
|
|
1626
|
+
}
|
|
1627
|
+
console.log("[HowOneProvider] Redirecting to:", authUrlObj.toString());
|
|
1628
|
+
window.location.href = authUrlObj.toString();
|
|
1629
|
+
} catch (error) {
|
|
1630
|
+
console.error("[HowOneProvider] Failed to build auth URL:", error);
|
|
1631
|
+
window.location.href = authUrl;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
|
|
1599
1636
|
const logout = () => {
|
|
1600
1637
|
try {
|
|
1601
1638
|
setToken(null);
|
|
@@ -2423,7 +2460,7 @@ export {
|
|
|
2423
2460
|
ErrorBoundary,
|
|
2424
2461
|
FloatingButton,
|
|
2425
2462
|
GlobalToastContainer,
|
|
2426
|
-
|
|
2463
|
+
HowOneProvider,
|
|
2427
2464
|
Loading,
|
|
2428
2465
|
LoadingSpinner,
|
|
2429
2466
|
LoginForm,
|