@sanvika/auth 2.9.0 → 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.
- package/dist/index.js +29 -5
- 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,
|
|
@@ -163,10 +180,13 @@ function SanvikaAuthProvider({
|
|
|
163
180
|
children,
|
|
164
181
|
clientId,
|
|
165
182
|
redirectUri,
|
|
183
|
+
/** RN embedded LoginScreen: skip callbackUrl on check-mobile/login APIs (OAuth URI still used for /authorize links). */
|
|
184
|
+
embeddedLogin = false,
|
|
166
185
|
dashboardPath,
|
|
167
186
|
authBaseUrl = DEFAULT_AUTH_URL,
|
|
168
187
|
persistence: persistenceProp
|
|
169
188
|
}) {
|
|
189
|
+
const apiCallbackUrl = embeddedLogin ? void 0 : redirectUri;
|
|
170
190
|
const persistence = useMemo(() => {
|
|
171
191
|
return persistenceProp || createDefaultWebPersistence();
|
|
172
192
|
}, [persistenceProp]);
|
|
@@ -215,10 +235,10 @@ function SanvikaAuthProvider({
|
|
|
215
235
|
mobile,
|
|
216
236
|
deviceId: resolvedDeviceId,
|
|
217
237
|
clientId,
|
|
218
|
-
callbackUrl:
|
|
238
|
+
callbackUrl: apiCallbackUrl
|
|
219
239
|
});
|
|
220
240
|
},
|
|
221
|
-
[authBaseUrl, clientId,
|
|
241
|
+
[authBaseUrl, clientId, apiCallbackUrl]
|
|
222
242
|
);
|
|
223
243
|
const login = async ({
|
|
224
244
|
mobile,
|
|
@@ -249,7 +269,7 @@ function SanvikaAuthProvider({
|
|
|
249
269
|
userAgent: userAgent || (typeof navigator !== "undefined" ? navigator.userAgent : void 0),
|
|
250
270
|
deviceName,
|
|
251
271
|
clientId,
|
|
252
|
-
callbackUrl:
|
|
272
|
+
callbackUrl: apiCallbackUrl,
|
|
253
273
|
resolveDeviceId
|
|
254
274
|
});
|
|
255
275
|
}
|
|
@@ -267,12 +287,14 @@ function SanvikaAuthProvider({
|
|
|
267
287
|
);
|
|
268
288
|
const logout = async () => {
|
|
269
289
|
try {
|
|
290
|
+
const deviceId = await resolveLogoutDeviceId(persistence);
|
|
270
291
|
await fetch(`${authBaseUrl}/api/auth/logout`, {
|
|
271
292
|
method: "POST",
|
|
272
293
|
headers: {
|
|
273
294
|
"Content-Type": "application/json",
|
|
274
295
|
...accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
|
|
275
|
-
}
|
|
296
|
+
},
|
|
297
|
+
body: JSON.stringify(deviceId ? { deviceId } : {})
|
|
276
298
|
});
|
|
277
299
|
} catch (e) {
|
|
278
300
|
console.error("[SanvikaAuth] Logout API error:", e);
|
|
@@ -651,7 +673,7 @@ function friendlyError(code) {
|
|
|
651
673
|
case "INVALID_PASSWORD":
|
|
652
674
|
return "Incorrect password.";
|
|
653
675
|
case "RATE_LIMIT_EXCEEDED":
|
|
654
|
-
return "Too many attempts. Please try again
|
|
676
|
+
return "Too many attempts. Please wait and try again.";
|
|
655
677
|
case "SERVER_ERROR":
|
|
656
678
|
return "Auth service error. Please try again.";
|
|
657
679
|
default:
|
|
@@ -844,6 +866,7 @@ export {
|
|
|
844
866
|
DEFAULT_AUTH_URL,
|
|
845
867
|
DEFAULT_AVATAR_SVG,
|
|
846
868
|
DEVICE_ID_STORAGE_KEY,
|
|
869
|
+
MOBILE_DEVICE_ID_STORAGE_KEY,
|
|
847
870
|
STORAGE_KEYS,
|
|
848
871
|
SanvikaAccountButton,
|
|
849
872
|
SanvikaAdminLogin,
|
|
@@ -854,5 +877,6 @@ export {
|
|
|
854
877
|
getOrCreateWebDeviceId,
|
|
855
878
|
postLogin,
|
|
856
879
|
randomDeviceId,
|
|
880
|
+
resolveLogoutDeviceId,
|
|
857
881
|
useSanvikaAuth
|
|
858
882
|
};
|