@sanvika/auth 1.0.26 → 2.0.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.
Files changed (2) hide show
  1. package/dist/index.js +15 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,40 +15,27 @@ import { jsx } from "react/jsx-runtime";
15
15
  var SA_URL = "https://accounts.sanvikaproduction.com";
16
16
  var SanvikaAuthContext = createContext(null);
17
17
  function SanvikaAuthProvider({ children }) {
18
- console.log("[SanvikaAuthProvider] Initializing provider...");
19
18
  const [user, setUser] = useState(null);
20
19
  const [accessToken, setToken] = useState(null);
21
20
  const [loading, setLoading] = useState(true);
22
21
  useEffect(() => {
23
- console.log("[SanvikaAuthProvider] Hydrating from localStorage...");
24
22
  try {
25
23
  const storedToken = localStorage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
26
24
  const storedUser = localStorage.getItem(STORAGE_KEYS.USER);
27
- console.log("[SanvikaAuthProvider] Token found:", !!storedToken);
28
- console.log("[SanvikaAuthProvider] User found:", !!storedUser);
29
25
  if (storedToken && storedUser) {
30
26
  setToken(storedToken);
31
27
  setUser(JSON.parse(storedUser));
32
- console.log(
33
- "[SanvikaAuthProvider] User loaded:",
34
- JSON.parse(storedUser).firstName
35
- );
36
28
  }
37
29
  } catch (e) {
38
30
  console.error("[SanvikaAuth] Failed to load from localStorage:", e);
39
31
  } finally {
40
32
  setLoading(false);
41
- console.log(
42
- "[SanvikaAuthProvider] Loading complete, isAuthenticated:",
43
- !!user
44
- );
45
33
  }
46
34
  }, []);
47
35
  const login = async ({ mobile, password, deviceId, deviceName }) => {
48
36
  const response = await fetch(`${SA_URL}/api/auth/login`, {
49
37
  method: "POST",
50
38
  headers: { "Content-Type": "application/json" },
51
- credentials: "include",
52
39
  body: JSON.stringify({
53
40
  mobile,
54
41
  password,
@@ -64,16 +51,14 @@ function SanvikaAuthProvider({ children }) {
64
51
  setUser(data.user);
65
52
  return data;
66
53
  };
67
- const logout = async (logoutAll = false) => {
54
+ const logout = async () => {
68
55
  try {
69
56
  await fetch(`${SA_URL}/api/auth/logout`, {
70
57
  method: "POST",
71
58
  headers: {
72
59
  "Content-Type": "application/json",
73
60
  Authorization: `Bearer ${accessToken}`
74
- },
75
- credentials: "include",
76
- body: JSON.stringify({ logout_all: logoutAll })
61
+ }
77
62
  });
78
63
  } catch (e) {
79
64
  console.error("[SanvikaAuth] Logout API error:", e);
@@ -92,11 +77,6 @@ function SanvikaAuthProvider({ children }) {
92
77
  login,
93
78
  logout
94
79
  };
95
- console.log("[SanvikaAuthProvider] Providing context value:", {
96
- user: (user == null ? void 0 : user.firstName) || null,
97
- loading,
98
- isAuthenticated: !!user
99
- });
100
80
  return /* @__PURE__ */ jsx(SanvikaAuthContext.Provider, { value, children });
101
81
  }
102
82
  function useSanvikaAuth() {
@@ -241,11 +221,22 @@ function SanvikaAccountButtonContent({
241
221
  "button",
242
222
  {
243
223
  className: `snvk-guestBtn ${className}`,
244
- onClick: () => {
245
- console.log("[SanvikaAccountButton] Guest button clicked, redirecting to /authorize");
224
+ onClick: (e) => {
225
+ console.log("[SanvikaAccountButton] \u2705\u2705\u2705 BUTTON CLICKED!");
226
+ console.log("[SanvikaAccountButton] Event target:", e.target);
227
+ console.log(
228
+ "[SanvikaAccountButton] Current URL:",
229
+ window.location.href
230
+ );
246
231
  if (onLoginClick) {
232
+ console.log("[SanvikaAccountButton] Calling custom onLoginClick");
247
233
  onLoginClick();
248
234
  } else {
235
+ console.log("[SanvikaAccountButton] Redirecting to /authorize...");
236
+ console.log(
237
+ "[SanvikaAccountButton] Target URL:",
238
+ window.location.origin + "/authorize"
239
+ );
249
240
  window.location.href = "/authorize";
250
241
  }
251
242
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "1.0.26",
3
+ "version": "2.0.0",
4
4
  "description": "Sanvika Auth SDK — React components and hooks for Sanvika SSO integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",