@howone/sdk 0.3.6 → 0.3.8

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 CHANGED
@@ -439,7 +439,7 @@ declare const AUTH_TOKEN_KEY = "auth_token";
439
439
  declare function setToken(token: string | null): void;
440
440
  declare function getToken(): string | null;
441
441
  declare function parseUserFromToken(token: string | null): {
442
- id: string;
442
+ id: {};
443
443
  email: string;
444
444
  name: string;
445
445
  avatar: string;
@@ -448,7 +448,7 @@ declare function isTokenValid(token: string | null): boolean;
448
448
  declare function useAuth(): {
449
449
  token: string | null;
450
450
  user: {
451
- id: string;
451
+ id: {};
452
452
  email: string;
453
453
  name: string;
454
454
  avatar: string;
@@ -855,7 +855,7 @@ declare function createClient(opts: {
855
855
  delete(id: string): Promise<void>;
856
856
  };
857
857
  me: () => Promise<{
858
- id: string;
858
+ id: {};
859
859
  email: string;
860
860
  name: string;
861
861
  avatar: string;
@@ -933,7 +933,7 @@ declare class HowoneAuthClient {
933
933
  login(): void;
934
934
  logout(): void;
935
935
  getUser(): {
936
- id: string;
936
+ id: {};
937
937
  email: string;
938
938
  name: string;
939
939
  avatar: string;
package/dist/index.d.ts CHANGED
@@ -439,7 +439,7 @@ declare const AUTH_TOKEN_KEY = "auth_token";
439
439
  declare function setToken(token: string | null): void;
440
440
  declare function getToken(): string | null;
441
441
  declare function parseUserFromToken(token: string | null): {
442
- id: string;
442
+ id: {};
443
443
  email: string;
444
444
  name: string;
445
445
  avatar: string;
@@ -448,7 +448,7 @@ declare function isTokenValid(token: string | null): boolean;
448
448
  declare function useAuth(): {
449
449
  token: string | null;
450
450
  user: {
451
- id: string;
451
+ id: {};
452
452
  email: string;
453
453
  name: string;
454
454
  avatar: string;
@@ -855,7 +855,7 @@ declare function createClient(opts: {
855
855
  delete(id: string): Promise<void>;
856
856
  };
857
857
  me: () => Promise<{
858
- id: string;
858
+ id: {};
859
859
  email: string;
860
860
  name: string;
861
861
  avatar: string;
@@ -933,7 +933,7 @@ declare class HowoneAuthClient {
933
933
  login(): void;
934
934
  logout(): void;
935
935
  getUser(): {
936
- id: string;
936
+ id: {};
937
937
  email: string;
938
938
  name: string;
939
939
  avatar: string;
package/dist/index.js CHANGED
@@ -172,7 +172,7 @@ function parseUserFromToken(token) {
172
172
  const payload = decodeJwtPayload(token);
173
173
  if (!payload) return null;
174
174
  return {
175
- id: payload.userId || payload.sub || "",
175
+ id: payload.puid || payload.userId || payload.sub || "",
176
176
  email: payload.email || "",
177
177
  name: payload.name || "",
178
178
  avatar: payload.avatar || payload.picture || ""
@@ -1395,34 +1395,42 @@ var HowOneProvider = ({
1395
1395
  injectRedirectOverlayStyles();
1396
1396
  }
1397
1397
  }, [pendingRedirect]);
1398
- (0, import_react8.useEffect)(() => {
1399
- if (!hasCheckedUrlToken) {
1400
- return;
1401
- }
1402
- if (redirectOnUnauthenticated && !token && !user) {
1398
+ const redirectToAuth = (0, import_react8.useCallback)(() => {
1399
+ if (!redirectOnUnauthenticated || typeof window === "undefined") return;
1400
+ try {
1403
1401
  const currentUrl = new URL(window.location.href);
1404
- if (!currentUrl.pathname.includes("/auth")) {
1405
- try {
1406
- const authUrlObj = new URL(resolvedAuthUrl);
1407
- const redirectUri = window.location.href;
1408
- authUrlObj.searchParams.set("redirect_uri", redirectUri);
1409
- if (projectId) {
1410
- authUrlObj.searchParams.set("project_id", projectId);
1411
- }
1412
- setPendingRedirect(true);
1413
- requestAnimationFrame(() => {
1414
- window.location.href = authUrlObj.toString();
1415
- });
1416
- } catch (error) {
1417
- console.error("[HowOneProvider] Failed to build auth URL:", error);
1418
- setPendingRedirect(true);
1419
- requestAnimationFrame(() => {
1420
- window.location.href = resolvedAuthUrl;
1421
- });
1402
+ if (currentUrl.pathname.includes("/auth")) return;
1403
+ try {
1404
+ const authUrlObj = new URL(resolvedAuthUrl);
1405
+ authUrlObj.searchParams.set("redirect_uri", window.location.href);
1406
+ if (projectId) {
1407
+ authUrlObj.searchParams.set("project_id", projectId);
1422
1408
  }
1409
+ setPendingRedirect(true);
1410
+ requestAnimationFrame(() => {
1411
+ window.location.href = authUrlObj.toString();
1412
+ });
1413
+ return;
1414
+ } catch (error) {
1415
+ console.error("[HowOneProvider] Failed to build auth URL:", error);
1423
1416
  }
1417
+ setPendingRedirect(true);
1418
+ requestAnimationFrame(() => {
1419
+ window.location.href = resolvedAuthUrl;
1420
+ });
1421
+ } catch {
1422
+ setPendingRedirect(true);
1423
+ requestAnimationFrame(() => {
1424
+ window.location.href = resolvedAuthUrl;
1425
+ });
1426
+ }
1427
+ }, [redirectOnUnauthenticated, resolvedAuthUrl, projectId]);
1428
+ (0, import_react8.useEffect)(() => {
1429
+ if (!hasCheckedUrlToken) return;
1430
+ if (!token && !user) {
1431
+ redirectToAuth();
1424
1432
  }
1425
- }, [token, user, redirectOnUnauthenticated, resolvedAuthUrl, projectId, hasCheckedUrlToken]);
1433
+ }, [token, user, hasCheckedUrlToken, redirectToAuth]);
1426
1434
  const logout = () => {
1427
1435
  try {
1428
1436
  setToken(null);
@@ -1430,6 +1438,7 @@ var HowOneProvider = ({
1430
1438
  }
1431
1439
  setTokenState(null);
1432
1440
  setUser(null);
1441
+ redirectToAuth();
1433
1442
  };
1434
1443
  const value = {
1435
1444
  user,
@@ -2082,7 +2091,7 @@ var createToast = (type) => {
2082
2091
  theme: getToastifyTheme(),
2083
2092
  // 确保圆角样式不被覆盖,添加 rounded-xl 类
2084
2093
  className: "!p-0 !shadow-none !rounded-xl",
2085
- style: { padding: 0, borderRadius: "0.75rem" }
2094
+ style: { padding: 0, borderRadius: "0.75rem", backgroundColor: "transparent" }
2086
2095
  }
2087
2096
  );
2088
2097
  };