@sanvika/auth 2.1.0 → 2.2.1

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 +22 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12,9 +12,16 @@ var DEFAULT_AVATAR_SVG = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/200
12
12
 
13
13
  // SanvikaAuthProvider.jsx
14
14
  import { jsx } from "react/jsx-runtime";
15
- var SA_URL = "https://accounts.sanvikaproduction.com";
15
+ var S_AUTH_URL = "https://accounts.sanvikaproduction.com";
16
16
  var SanvikaAuthContext = createContext(null);
17
- function SanvikaAuthProvider({ children }) {
17
+ function SanvikaAuthProvider({
18
+ children,
19
+ clientId,
20
+ redirectUri,
21
+ saUrl: saUrlProp,
22
+ dashboardPath
23
+ }) {
24
+ const saBaseUrl = saUrlProp || S_AUTH_URL;
18
25
  const [user, setUser] = useState(null);
19
26
  const [accessToken, setToken] = useState(null);
20
27
  const [loading, setLoading] = useState(true);
@@ -33,7 +40,7 @@ function SanvikaAuthProvider({ children }) {
33
40
  }
34
41
  }, []);
35
42
  const login = async ({ mobile, password, deviceId, deviceName }) => {
36
- const response = await fetch(`${SA_URL}/api/auth/login`, {
43
+ const response = await fetch(`${S_AUTH_URL}/api/auth/login`, {
37
44
  method: "POST",
38
45
  headers: { "Content-Type": "application/json" },
39
46
  body: JSON.stringify({
@@ -59,7 +66,7 @@ function SanvikaAuthProvider({ children }) {
59
66
  };
60
67
  const logout = async () => {
61
68
  try {
62
- await fetch(`${SA_URL}/api/auth/logout`, {
69
+ await fetch(`${S_AUTH_URL}/api/auth/logout`, {
63
70
  method: "POST",
64
71
  headers: {
65
72
  "Content-Type": "application/json",
@@ -82,7 +89,11 @@ function SanvikaAuthProvider({ children }) {
82
89
  isAuthenticated: !!user,
83
90
  login,
84
91
  logout,
85
- setAuth
92
+ setAuth,
93
+ clientId,
94
+ redirectUri,
95
+ saBaseUrl,
96
+ dashboardPath
86
97
  };
87
98
  return /* @__PURE__ */ jsx(SanvikaAuthContext.Provider, { value, children });
88
99
  }
@@ -205,9 +216,6 @@ function SanvikaAccountButtonContent({
205
216
  }) {
206
217
  var _a, _b;
207
218
  const auth = useSanvikaAuth();
208
- console.log("[SanvikaAccountButton] auth context:", auth);
209
- console.log("[SanvikaAccountButton] auth type:", typeof auth);
210
- console.log("[SanvikaAccountButton] auth is null:", auth === null);
211
219
  const [dropdownOpen, setDropdownOpen] = useState2(false);
212
220
  const [imgError, setImgError] = useState2(false);
213
221
  const [prevImage, setPrevImage] = useState2((_a = auth == null ? void 0 : auth.user) == null ? void 0 : _a.image);
@@ -223,28 +231,15 @@ function SanvikaAccountButtonContent({
223
231
  return () => document.removeEventListener("mousedown", handleOutside);
224
232
  }, [dropdownOpen]);
225
233
  if (!auth) {
226
- console.log("[SanvikaAccountButton] Auth is null, showing guest button");
227
234
  return /* @__PURE__ */ jsxs(
228
235
  "button",
229
236
  {
230
237
  className: `snvk-guestBtn ${className}`,
231
238
  onClick: (e) => {
232
- console.log("[SanvikaAccountButton] \u2705\u2705\u2705 BUTTON CLICKED!");
233
- console.log("[SanvikaAccountButton] Event target:", e.target);
234
- console.log(
235
- "[SanvikaAccountButton] Current URL:",
236
- window.location.href
237
- );
238
239
  if (onLoginClick) {
239
- console.log("[SanvikaAccountButton] Calling custom onLoginClick");
240
240
  onLoginClick();
241
241
  } else {
242
- console.log("[SanvikaAccountButton] Redirecting to /authorize...");
243
- console.log(
244
- "[SanvikaAccountButton] Target URL:",
245
- window.location.origin + "/authorize"
246
- );
247
- window.location.href = "/authorize";
242
+ window.location.href = "https://accounts.sanvikaproduction.com/authorize";
248
243
  }
249
244
  },
250
245
  "aria-label": "Login or Sign Up",
@@ -267,19 +262,17 @@ function SanvikaAccountButtonContent({
267
262
  setImgError(false);
268
263
  }
269
264
  if (!isAuthenticated || loading) {
265
+ const { clientId, redirectUri, saBaseUrl } = auth;
266
+ const authorizeUrl = clientId && redirectUri ? `${saBaseUrl}/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(redirectUri)}` : `${saBaseUrl}/authorize`;
270
267
  return /* @__PURE__ */ jsxs(
271
268
  "button",
272
269
  {
273
270
  className: `snvk-guestBtn ${className}`,
274
271
  onClick: (e) => {
275
- console.log("[SanvikaAccountButton] \u2705\u2705\u2705 BUTTON CLICKED!");
276
- console.log("[SanvikaAccountButton] Event target:", e.target);
277
272
  if (onLoginClick) {
278
- console.log("[SanvikaAccountButton] Calling custom onLoginClick");
279
273
  onLoginClick();
280
274
  } else {
281
- console.log("[SanvikaAccountButton] Redirecting to /authorize...");
282
- window.location.href = "/authorize";
275
+ window.location.href = authorizeUrl;
283
276
  }
284
277
  },
285
278
  "aria-label": "Login or Sign Up",
@@ -300,7 +293,7 @@ function SanvikaAccountButtonContent({
300
293
  const imageSrc = !imgError && user.image ? user.image : DEFAULT_AVATAR_SVG;
301
294
  const handleProfileClick = () => {
302
295
  if (onProfileClick) return onProfileClick();
303
- window.location.href = "https://accounts.sanvikaproduction.com/dashboard";
296
+ window.location.href = (auth == null ? void 0 : auth.dashboardPath) || "https://accounts.sanvikaproduction.com/dashboard";
304
297
  };
305
298
  const handleLogout = async () => {
306
299
  await logout(false);
@@ -359,7 +352,7 @@ function SanvikaAccountButtonContent({
359
352
  /* @__PURE__ */ jsxs(
360
353
  "a",
361
354
  {
362
- href: "/dashboard",
355
+ href: (auth == null ? void 0 : auth.dashboardPath) || "/dashboard",
363
356
  className: "snvk-dropdownItem",
364
357
  role: "menuitem",
365
358
  onClick: () => setDropdownOpen(false),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Sanvika Auth SDK — React components and hooks for Sanvika SSO integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",