@sanvika/auth 1.0.27 → 2.1.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 +24 -27
  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,20 @@ function SanvikaAuthProvider({ children }) {
64
51
  setUser(data.user);
65
52
  return data;
66
53
  };
67
- const logout = async (logoutAll = false) => {
54
+ const setAuth = (token, userData) => {
55
+ localStorage.setItem(STORAGE_KEYS.ACCESS_TOKEN, token);
56
+ localStorage.setItem(STORAGE_KEYS.USER, JSON.stringify(userData));
57
+ setToken(token);
58
+ setUser(userData);
59
+ };
60
+ const logout = async () => {
68
61
  try {
69
62
  await fetch(`${SA_URL}/api/auth/logout`, {
70
63
  method: "POST",
71
64
  headers: {
72
65
  "Content-Type": "application/json",
73
66
  Authorization: `Bearer ${accessToken}`
74
- },
75
- credentials: "include",
76
- body: JSON.stringify({ logout_all: logoutAll })
67
+ }
77
68
  });
78
69
  } catch (e) {
79
70
  console.error("[SanvikaAuth] Logout API error:", e);
@@ -90,13 +81,9 @@ function SanvikaAuthProvider({ children }) {
90
81
  loading,
91
82
  isAuthenticated: !!user,
92
83
  login,
93
- logout
84
+ logout,
85
+ setAuth
94
86
  };
95
- console.log("[SanvikaAuthProvider] Providing context value:", {
96
- user: (user == null ? void 0 : user.firstName) || null,
97
- loading,
98
- isAuthenticated: !!user
99
- });
100
87
  return /* @__PURE__ */ jsx(SanvikaAuthContext.Provider, { value, children });
101
88
  }
102
89
  function useSanvikaAuth() {
@@ -244,13 +231,19 @@ function SanvikaAccountButtonContent({
244
231
  onClick: (e) => {
245
232
  console.log("[SanvikaAccountButton] \u2705\u2705\u2705 BUTTON CLICKED!");
246
233
  console.log("[SanvikaAccountButton] Event target:", e.target);
247
- console.log("[SanvikaAccountButton] Current URL:", window.location.href);
234
+ console.log(
235
+ "[SanvikaAccountButton] Current URL:",
236
+ window.location.href
237
+ );
248
238
  if (onLoginClick) {
249
239
  console.log("[SanvikaAccountButton] Calling custom onLoginClick");
250
240
  onLoginClick();
251
241
  } else {
252
242
  console.log("[SanvikaAccountButton] Redirecting to /authorize...");
253
- console.log("[SanvikaAccountButton] Target URL:", window.location.origin + "/authorize");
243
+ console.log(
244
+ "[SanvikaAccountButton] Target URL:",
245
+ window.location.origin + "/authorize"
246
+ );
254
247
  window.location.href = "/authorize";
255
248
  }
256
249
  },
@@ -278,11 +271,15 @@ function SanvikaAccountButtonContent({
278
271
  "button",
279
272
  {
280
273
  className: `snvk-guestBtn ${className}`,
281
- onClick: () => {
274
+ onClick: (e) => {
275
+ console.log("[SanvikaAccountButton] \u2705\u2705\u2705 BUTTON CLICKED!");
276
+ console.log("[SanvikaAccountButton] Event target:", e.target);
282
277
  if (onLoginClick) {
278
+ console.log("[SanvikaAccountButton] Calling custom onLoginClick");
283
279
  onLoginClick();
284
280
  } else {
285
- window.location.href = "https://accounts.sanvikaproduction.com";
281
+ console.log("[SanvikaAccountButton] Redirecting to /authorize...");
282
+ window.location.href = "/authorize";
286
283
  }
287
284
  },
288
285
  "aria-label": "Login or Sign Up",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "1.0.27",
3
+ "version": "2.1.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",