@sanvika/auth 2.1.0 → 2.2.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.
- package/dist/index.js +24 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,14 @@ var DEFAULT_AVATAR_SVG = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/200
|
|
|
14
14
|
import { jsx } from "react/jsx-runtime";
|
|
15
15
|
var SA_URL = "https://accounts.sanvikaproduction.com";
|
|
16
16
|
var SanvikaAuthContext = createContext(null);
|
|
17
|
-
function SanvikaAuthProvider({
|
|
17
|
+
function SanvikaAuthProvider({
|
|
18
|
+
children,
|
|
19
|
+
clientId,
|
|
20
|
+
redirectUri,
|
|
21
|
+
saUrl: saUrlProp,
|
|
22
|
+
dashboardPath
|
|
23
|
+
}) {
|
|
24
|
+
const saBaseUrl = saUrlProp || SA_URL;
|
|
18
25
|
const [user, setUser] = useState(null);
|
|
19
26
|
const [accessToken, setToken] = useState(null);
|
|
20
27
|
const [loading, setLoading] = useState(true);
|
|
@@ -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
|
}
|
|
@@ -239,12 +250,10 @@ function SanvikaAccountButtonContent({
|
|
|
239
250
|
console.log("[SanvikaAccountButton] Calling custom onLoginClick");
|
|
240
251
|
onLoginClick();
|
|
241
252
|
} else {
|
|
242
|
-
console.log("[SanvikaAccountButton] Redirecting to /authorize...");
|
|
243
253
|
console.log(
|
|
244
|
-
"[SanvikaAccountButton]
|
|
245
|
-
window.location.origin + "/authorize"
|
|
254
|
+
"[SanvikaAccountButton] Redirecting to SA authorize..."
|
|
246
255
|
);
|
|
247
|
-
window.location.href = "/authorize";
|
|
256
|
+
window.location.href = "https://accounts.sanvikaproduction.com/authorize";
|
|
248
257
|
}
|
|
249
258
|
},
|
|
250
259
|
"aria-label": "Login or Sign Up",
|
|
@@ -267,6 +276,8 @@ function SanvikaAccountButtonContent({
|
|
|
267
276
|
setImgError(false);
|
|
268
277
|
}
|
|
269
278
|
if (!isAuthenticated || loading) {
|
|
279
|
+
const { clientId, redirectUri, saBaseUrl } = auth;
|
|
280
|
+
const authorizeUrl = clientId && redirectUri ? `${saBaseUrl}/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(redirectUri)}` : `${saBaseUrl}/authorize`;
|
|
270
281
|
return /* @__PURE__ */ jsxs(
|
|
271
282
|
"button",
|
|
272
283
|
{
|
|
@@ -278,8 +289,11 @@ function SanvikaAccountButtonContent({
|
|
|
278
289
|
console.log("[SanvikaAccountButton] Calling custom onLoginClick");
|
|
279
290
|
onLoginClick();
|
|
280
291
|
} else {
|
|
281
|
-
console.log(
|
|
282
|
-
|
|
292
|
+
console.log(
|
|
293
|
+
"[SanvikaAccountButton] Redirecting to SA authorize...",
|
|
294
|
+
authorizeUrl
|
|
295
|
+
);
|
|
296
|
+
window.location.href = authorizeUrl;
|
|
283
297
|
}
|
|
284
298
|
},
|
|
285
299
|
"aria-label": "Login or Sign Up",
|
|
@@ -300,7 +314,7 @@ function SanvikaAccountButtonContent({
|
|
|
300
314
|
const imageSrc = !imgError && user.image ? user.image : DEFAULT_AVATAR_SVG;
|
|
301
315
|
const handleProfileClick = () => {
|
|
302
316
|
if (onProfileClick) return onProfileClick();
|
|
303
|
-
window.location.href = "https://accounts.sanvikaproduction.com/dashboard";
|
|
317
|
+
window.location.href = (auth == null ? void 0 : auth.dashboardPath) || "https://accounts.sanvikaproduction.com/dashboard";
|
|
304
318
|
};
|
|
305
319
|
const handleLogout = async () => {
|
|
306
320
|
await logout(false);
|
|
@@ -359,7 +373,7 @@ function SanvikaAccountButtonContent({
|
|
|
359
373
|
/* @__PURE__ */ jsxs(
|
|
360
374
|
"a",
|
|
361
375
|
{
|
|
362
|
-
href: "/dashboard",
|
|
376
|
+
href: (auth == null ? void 0 : auth.dashboardPath) || "/dashboard",
|
|
363
377
|
className: "snvk-dropdownItem",
|
|
364
378
|
role: "menuitem",
|
|
365
379
|
onClick: () => setDropdownOpen(false),
|