@sanvika/auth 2.9.1 → 2.9.2

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 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var DEFAULT_AVATAR_SVG = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/200
20
20
  // authFlow.js
21
21
  var DEFAULT_AUTH_URL = "https://auth.sanvikaproduction.com";
22
22
  var DEVICE_ID_STORAGE_KEY = "sanvika_deviceId";
23
+ var MOBILE_DEVICE_ID_STORAGE_KEY = "deviceId";
23
24
  function randomDeviceId() {
24
25
  try {
25
26
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -44,6 +45,22 @@ function getOrCreateWebDeviceId() {
44
45
  }
45
46
  return deviceId;
46
47
  }
48
+ async function resolveLogoutDeviceId(persistence) {
49
+ if (persistence == null ? void 0 : persistence.getItem) {
50
+ try {
51
+ const mobileId = await persistence.getItem(MOBILE_DEVICE_ID_STORAGE_KEY);
52
+ if (mobileId) {
53
+ return mobileId;
54
+ }
55
+ const webId = await persistence.getItem(DEVICE_ID_STORAGE_KEY);
56
+ if (webId) {
57
+ return webId;
58
+ }
59
+ } catch {
60
+ }
61
+ }
62
+ return getOrCreateWebDeviceId();
63
+ }
47
64
  async function checkMobile({
48
65
  authBaseUrl = DEFAULT_AUTH_URL,
49
66
  mobile,
@@ -270,12 +287,14 @@ function SanvikaAuthProvider({
270
287
  );
271
288
  const logout = async () => {
272
289
  try {
290
+ const deviceId = await resolveLogoutDeviceId(persistence);
273
291
  await fetch(`${authBaseUrl}/api/auth/logout`, {
274
292
  method: "POST",
275
293
  headers: {
276
294
  "Content-Type": "application/json",
277
295
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
278
- }
296
+ },
297
+ body: JSON.stringify(deviceId ? { deviceId } : {})
279
298
  });
280
299
  } catch (e) {
281
300
  console.error("[SanvikaAuth] Logout API error:", e);
@@ -847,6 +866,7 @@ export {
847
866
  DEFAULT_AUTH_URL,
848
867
  DEFAULT_AVATAR_SVG,
849
868
  DEVICE_ID_STORAGE_KEY,
869
+ MOBILE_DEVICE_ID_STORAGE_KEY,
850
870
  STORAGE_KEYS,
851
871
  SanvikaAccountButton,
852
872
  SanvikaAdminLogin,
@@ -857,5 +877,6 @@ export {
857
877
  getOrCreateWebDeviceId,
858
878
  postLogin,
859
879
  randomDeviceId,
880
+ resolveLogoutDeviceId,
860
881
  useSanvikaAuth
861
882
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "Sanvika Auth SDK — React components/hooks + server-side token verification and user proxy",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",