shogun-button-react 1.5.30 β 1.5.31
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/components/ShogunButton.js +94 -11
- package/dist/dist/styles/index.css +26 -0
- package/dist/styles/index.css +26 -0
- package/package.json +1 -1
- package/src/styles/index.css +26 -0
|
@@ -31,18 +31,52 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
31
31
|
// Effetto per gestire l'inizializzazione e pulizia
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
var _a, _b;
|
|
34
|
+
console.log(`π§ ShogunButtonProvider useEffect - SDK available:`, !!sdk);
|
|
34
35
|
if (!sdk)
|
|
35
36
|
return;
|
|
37
|
+
// Check for existing session data
|
|
38
|
+
const sessionData = sessionStorage.getItem("gunSessionData");
|
|
39
|
+
const pairData = sessionStorage.getItem("gun/pair") || sessionStorage.getItem("pair");
|
|
40
|
+
console.log(`π§ Session data available:`, {
|
|
41
|
+
hasSessionData: !!sessionData,
|
|
42
|
+
hasPairData: !!pairData,
|
|
43
|
+
});
|
|
36
44
|
// Verifichiamo se l'utente Γ¨ giΓ loggato all'inizializzazione
|
|
37
45
|
// Aggiungiamo un controllo di sicurezza per verificare se il metodo esiste
|
|
38
|
-
if (sdk && typeof sdk.isLoggedIn === "function"
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
if (sdk && typeof sdk.isLoggedIn === "function") {
|
|
47
|
+
const isLoggedIn = sdk.isLoggedIn();
|
|
48
|
+
console.log(`π§ SDK isLoggedIn(): ${isLoggedIn}`);
|
|
49
|
+
if (isLoggedIn) {
|
|
50
|
+
const pub = (_b = (_a = sdk.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub;
|
|
51
|
+
console.log(`π§ User already logged in with pub: ${pub === null || pub === void 0 ? void 0 : pub.slice(0, 8)}...`);
|
|
52
|
+
if (pub) {
|
|
53
|
+
console.log(`π§ Setting user state from existing session`);
|
|
54
|
+
setIsLoggedIn(true);
|
|
55
|
+
setUserPub(pub);
|
|
56
|
+
setUsername(pub.slice(0, 8) + "...");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.log(`π§ User not logged in`);
|
|
61
|
+
// Try to restore session if we have pair data
|
|
62
|
+
if (pairData && !isLoggedIn) {
|
|
63
|
+
console.log(`π§ Attempting to restore session from pair data`);
|
|
64
|
+
try {
|
|
65
|
+
const pair = JSON.parse(pairData);
|
|
66
|
+
if (pair.pub) {
|
|
67
|
+
console.log(`π§ Found pair with pub: ${pair.pub.slice(0, 8)}...`);
|
|
68
|
+
// Don't auto-login, just log the available data
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(`π§ Error parsing pair data:`, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
44
75
|
}
|
|
45
76
|
}
|
|
77
|
+
else {
|
|
78
|
+
console.log(`π§ SDK isLoggedIn method not available`);
|
|
79
|
+
}
|
|
46
80
|
// PoichΓ© il metodo 'on' non esiste su ShogunCore,
|
|
47
81
|
// gestiamo gli stati direttamente nei metodi di login/logout
|
|
48
82
|
}, [sdk, onLoginSuccess]);
|
|
@@ -55,7 +89,8 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
55
89
|
};
|
|
56
90
|
// Unified login
|
|
57
91
|
const login = async (method, ...args) => {
|
|
58
|
-
var _a, _b;
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
console.log(`π§ ShogunButtonProvider.login called with method: ${method}`, args);
|
|
59
94
|
try {
|
|
60
95
|
if (!sdk) {
|
|
61
96
|
throw new Error("SDK not initialized");
|
|
@@ -63,9 +98,11 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
63
98
|
let result;
|
|
64
99
|
let authMethod = method;
|
|
65
100
|
let username;
|
|
101
|
+
console.log(`π§ Processing login method: ${method}`);
|
|
66
102
|
switch (method) {
|
|
67
103
|
case "password":
|
|
68
104
|
username = args[0];
|
|
105
|
+
console.log(`π§ Password login for username: ${username}`);
|
|
69
106
|
result = await sdk.login(args[0], args[1]);
|
|
70
107
|
break;
|
|
71
108
|
case "pair":
|
|
@@ -74,6 +111,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
74
111
|
if (!pair || typeof pair !== "object") {
|
|
75
112
|
throw new Error("Invalid pair data provided");
|
|
76
113
|
}
|
|
114
|
+
console.log(`π§ Pair login with pub: ${(_a = pair.pub) === null || _a === void 0 ? void 0 : _a.slice(0, 8)}...`);
|
|
77
115
|
result = await new Promise((resolve, reject) => {
|
|
78
116
|
sdk.gun.user().auth(pair, (ack) => {
|
|
79
117
|
if (ack.err) {
|
|
@@ -95,6 +133,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
95
133
|
break;
|
|
96
134
|
case "webauthn":
|
|
97
135
|
username = args[0];
|
|
136
|
+
console.log(`π§ WebAuthn login for username: ${username}`);
|
|
98
137
|
const webauthn = sdk.getPlugin("webauthn");
|
|
99
138
|
if (!webauthn)
|
|
100
139
|
throw new Error("WebAuthn plugin not available");
|
|
@@ -102,6 +141,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
102
141
|
authMethod = "webauthn";
|
|
103
142
|
break;
|
|
104
143
|
case "web3":
|
|
144
|
+
console.log(`π§ Web3 login initiated`);
|
|
105
145
|
const web3 = sdk.getPlugin("web3");
|
|
106
146
|
if (!web3)
|
|
107
147
|
throw new Error("Web3 plugin not available");
|
|
@@ -110,10 +150,12 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
110
150
|
throw new Error(connectionResult.error || "Failed to connect wallet.");
|
|
111
151
|
}
|
|
112
152
|
username = connectionResult.address;
|
|
153
|
+
console.log(`π§ Web3 connected to address: ${username}`);
|
|
113
154
|
result = await web3.login(connectionResult.address);
|
|
114
155
|
authMethod = "web3";
|
|
115
156
|
break;
|
|
116
157
|
case "nostr":
|
|
158
|
+
console.log(`π§ Nostr login initiated`);
|
|
117
159
|
const nostr = sdk.getPlugin("nostr");
|
|
118
160
|
if (!nostr)
|
|
119
161
|
throw new Error("Nostr plugin not available");
|
|
@@ -125,10 +167,12 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
125
167
|
if (!pubkey)
|
|
126
168
|
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
127
169
|
username = pubkey;
|
|
170
|
+
console.log(`π§ Nostr connected to pubkey: ${username}`);
|
|
128
171
|
result = await nostr.login(pubkey);
|
|
129
172
|
authMethod = "nostr";
|
|
130
173
|
break;
|
|
131
174
|
case "oauth":
|
|
175
|
+
console.log(`π§ OAuth login initiated`);
|
|
132
176
|
const oauth = sdk.getPlugin("oauth");
|
|
133
177
|
if (!oauth)
|
|
134
178
|
throw new Error("OAuth plugin not available");
|
|
@@ -151,9 +195,15 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
151
195
|
default:
|
|
152
196
|
throw new Error("Unsupported login method");
|
|
153
197
|
}
|
|
198
|
+
console.log(`π§ Login result:`, result);
|
|
154
199
|
if (result.success) {
|
|
155
|
-
const userPub = result.userPub || ((
|
|
200
|
+
const userPub = result.userPub || ((_c = (_b = sdk.gun.user()) === null || _b === void 0 ? void 0 : _b.is) === null || _c === void 0 ? void 0 : _c.pub) || "";
|
|
156
201
|
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
202
|
+
console.log(`π§ Login successful! Setting user state:`, {
|
|
203
|
+
userPub: userPub.slice(0, 8) + "...",
|
|
204
|
+
displayName,
|
|
205
|
+
authMethod,
|
|
206
|
+
});
|
|
157
207
|
setIsLoggedIn(true);
|
|
158
208
|
setUserPub(userPub);
|
|
159
209
|
setUsername(displayName);
|
|
@@ -164,11 +214,13 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
164
214
|
});
|
|
165
215
|
}
|
|
166
216
|
else {
|
|
217
|
+
console.error(`π§ Login failed:`, result.error);
|
|
167
218
|
onError === null || onError === void 0 ? void 0 : onError(result.error || "Login failed");
|
|
168
219
|
}
|
|
169
220
|
return result;
|
|
170
221
|
}
|
|
171
222
|
catch (error) {
|
|
223
|
+
console.error(`π§ Login error:`, error);
|
|
172
224
|
onError === null || onError === void 0 ? void 0 : onError(error.message || "Error during login");
|
|
173
225
|
return { success: false, error: error.message };
|
|
174
226
|
}
|
|
@@ -482,26 +534,39 @@ export const ShogunButton = (() => {
|
|
|
482
534
|
}
|
|
483
535
|
// Event handlers
|
|
484
536
|
const handleAuth = async (method, ...args) => {
|
|
537
|
+
console.log(`π§ handleAuth called with method: ${method}`, args);
|
|
485
538
|
setError("");
|
|
486
539
|
setLoading(true);
|
|
487
540
|
try {
|
|
488
541
|
// Use formMode to determine whether to call login or signUp
|
|
489
542
|
const action = formMode === "login" ? login : signUp;
|
|
543
|
+
console.log(`π§ Using action: ${formMode === "login" ? "login" : "signUp"}`);
|
|
544
|
+
console.log(`π§ Calling ${action.name} with method: ${method}`);
|
|
490
545
|
const result = await action(method, ...args);
|
|
546
|
+
console.log(`π§ ${action.name} result:`, result);
|
|
491
547
|
if (result && !result.success && result.error) {
|
|
548
|
+
console.error(`π§ ${action.name} failed with error:`, result.error);
|
|
492
549
|
setError(result.error);
|
|
493
550
|
}
|
|
494
551
|
else if (result && result.redirectUrl) {
|
|
552
|
+
console.log(`π§ Redirecting to: ${result.redirectUrl}`);
|
|
495
553
|
window.location.href = result.redirectUrl;
|
|
496
554
|
}
|
|
555
|
+
else if (result && result.success) {
|
|
556
|
+
console.log(`π§ ${action.name} successful, closing modal`);
|
|
557
|
+
setModalIsOpen(false);
|
|
558
|
+
}
|
|
497
559
|
else {
|
|
560
|
+
console.warn(`π§ Unexpected result:`, result);
|
|
498
561
|
setModalIsOpen(false);
|
|
499
562
|
}
|
|
500
563
|
}
|
|
501
564
|
catch (e) {
|
|
565
|
+
console.error(`π§ handleAuth error:`, e);
|
|
502
566
|
setError(e.message || "An unexpected error occurred.");
|
|
503
567
|
}
|
|
504
568
|
finally {
|
|
569
|
+
console.log(`π§ handleAuth completed, setting loading to false`);
|
|
505
570
|
setLoading(false);
|
|
506
571
|
}
|
|
507
572
|
};
|
|
@@ -639,9 +704,15 @@ export const ShogunButton = (() => {
|
|
|
639
704
|
setModalIsOpen(false);
|
|
640
705
|
};
|
|
641
706
|
const toggleMode = () => {
|
|
707
|
+
console.log("π§ toggleMode called - current formMode:", formMode);
|
|
708
|
+
console.log("π§ loading state:", loading);
|
|
642
709
|
resetForm();
|
|
643
710
|
setAuthView("options"); // Porta alla selezione dei metodi invece che direttamente al form password
|
|
644
|
-
setFormMode((prev) =>
|
|
711
|
+
setFormMode((prev) => {
|
|
712
|
+
const newMode = prev === "login" ? "signup" : "login";
|
|
713
|
+
console.log("π§ Switching from", prev, "to", newMode);
|
|
714
|
+
return newMode;
|
|
715
|
+
});
|
|
645
716
|
};
|
|
646
717
|
// Add buttons for both login and signup for alternative auth methods
|
|
647
718
|
const renderAuthOptions = () => (React.createElement("div", { className: "shogun-auth-options" },
|
|
@@ -715,7 +786,13 @@ export const ShogunButton = (() => {
|
|
|
715
786
|
? "Sign In"
|
|
716
787
|
: "Create Account"),
|
|
717
788
|
React.createElement("div", { className: "shogun-form-footer" },
|
|
718
|
-
React.createElement("button", { type: "button", className: "shogun-toggle-mode shogun-prominent-toggle", onClick:
|
|
789
|
+
React.createElement("button", { type: "button", className: "shogun-toggle-mode shogun-prominent-toggle", onClick: () => {
|
|
790
|
+
console.log("π§ Signup button clicked!");
|
|
791
|
+
console.log("π§ Current formMode:", formMode);
|
|
792
|
+
console.log("π§ Current loading:", loading);
|
|
793
|
+
console.log("π§ Current authView:", authView);
|
|
794
|
+
toggleMode();
|
|
795
|
+
}, disabled: loading }, formMode === "login"
|
|
719
796
|
? "Don't have an account? Sign up"
|
|
720
797
|
: "Already have an account? Log in"),
|
|
721
798
|
formMode === "login" && (React.createElement("button", { type: "button", className: "shogun-toggle-mode", onClick: () => setAuthView("recover"), disabled: loading }, "Forgot password?")))));
|
|
@@ -912,7 +989,13 @@ export const ShogunButton = (() => {
|
|
|
912
989
|
authView === "options" && (React.createElement(React.Fragment, null,
|
|
913
990
|
renderAuthOptions(),
|
|
914
991
|
React.createElement("div", { className: "shogun-form-footer" },
|
|
915
|
-
React.createElement("button", { type: "button", className: "shogun-toggle-mode shogun-prominent-toggle", onClick:
|
|
992
|
+
React.createElement("button", { type: "button", className: "shogun-toggle-mode shogun-prominent-toggle", onClick: () => {
|
|
993
|
+
console.log("π§ Signup button clicked!");
|
|
994
|
+
console.log("π§ Current formMode:", formMode);
|
|
995
|
+
console.log("π§ Current loading:", loading);
|
|
996
|
+
console.log("π§ Current authView:", authView);
|
|
997
|
+
toggleMode();
|
|
998
|
+
}, disabled: loading }, formMode === "login"
|
|
916
999
|
? "Don't have an account? Sign up"
|
|
917
1000
|
: "Already have an account? Log in")))),
|
|
918
1001
|
authView === "password" && (React.createElement(React.Fragment, null,
|
|
@@ -445,10 +445,36 @@
|
|
|
445
445
|
border-radius: 6px;
|
|
446
446
|
background-color: transparent;
|
|
447
447
|
transition: all 0.2s ease;
|
|
448
|
+
cursor: pointer;
|
|
449
|
+
display: inline-block;
|
|
450
|
+
text-decoration: none;
|
|
451
|
+
font-size: 14px;
|
|
452
|
+
line-height: 1.4;
|
|
453
|
+
min-height: 44px;
|
|
454
|
+
display: flex;
|
|
455
|
+
align-items: center;
|
|
456
|
+
justify-content: center;
|
|
448
457
|
}
|
|
449
458
|
|
|
450
459
|
.shogun-prominent-toggle:hover {
|
|
451
460
|
text-decoration: underline;
|
|
461
|
+
background-color: rgba(59, 130, 246, 0.1);
|
|
462
|
+
transform: translateY(-1px);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.shogun-prominent-toggle:active {
|
|
466
|
+
transform: translateY(0);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.shogun-prominent-toggle:disabled {
|
|
470
|
+
opacity: 0.5;
|
|
471
|
+
cursor: not-allowed;
|
|
472
|
+
pointer-events: none;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.shogun-prominent-toggle:focus {
|
|
476
|
+
outline: 2px solid var(--shogun-primary);
|
|
477
|
+
outline-offset: 2px;
|
|
452
478
|
}
|
|
453
479
|
|
|
454
480
|
/* Redundant dark theme styles removed */
|
package/dist/styles/index.css
CHANGED
|
@@ -445,10 +445,36 @@
|
|
|
445
445
|
border-radius: 6px;
|
|
446
446
|
background-color: transparent;
|
|
447
447
|
transition: all 0.2s ease;
|
|
448
|
+
cursor: pointer;
|
|
449
|
+
display: inline-block;
|
|
450
|
+
text-decoration: none;
|
|
451
|
+
font-size: 14px;
|
|
452
|
+
line-height: 1.4;
|
|
453
|
+
min-height: 44px;
|
|
454
|
+
display: flex;
|
|
455
|
+
align-items: center;
|
|
456
|
+
justify-content: center;
|
|
448
457
|
}
|
|
449
458
|
|
|
450
459
|
.shogun-prominent-toggle:hover {
|
|
451
460
|
text-decoration: underline;
|
|
461
|
+
background-color: rgba(59, 130, 246, 0.1);
|
|
462
|
+
transform: translateY(-1px);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.shogun-prominent-toggle:active {
|
|
466
|
+
transform: translateY(0);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.shogun-prominent-toggle:disabled {
|
|
470
|
+
opacity: 0.5;
|
|
471
|
+
cursor: not-allowed;
|
|
472
|
+
pointer-events: none;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.shogun-prominent-toggle:focus {
|
|
476
|
+
outline: 2px solid var(--shogun-primary);
|
|
477
|
+
outline-offset: 2px;
|
|
452
478
|
}
|
|
453
479
|
|
|
454
480
|
/* Redundant dark theme styles removed */
|
package/package.json
CHANGED
package/src/styles/index.css
CHANGED
|
@@ -445,10 +445,36 @@
|
|
|
445
445
|
border-radius: 6px;
|
|
446
446
|
background-color: transparent;
|
|
447
447
|
transition: all 0.2s ease;
|
|
448
|
+
cursor: pointer;
|
|
449
|
+
display: inline-block;
|
|
450
|
+
text-decoration: none;
|
|
451
|
+
font-size: 14px;
|
|
452
|
+
line-height: 1.4;
|
|
453
|
+
min-height: 44px;
|
|
454
|
+
display: flex;
|
|
455
|
+
align-items: center;
|
|
456
|
+
justify-content: center;
|
|
448
457
|
}
|
|
449
458
|
|
|
450
459
|
.shogun-prominent-toggle:hover {
|
|
451
460
|
text-decoration: underline;
|
|
461
|
+
background-color: rgba(59, 130, 246, 0.1);
|
|
462
|
+
transform: translateY(-1px);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.shogun-prominent-toggle:active {
|
|
466
|
+
transform: translateY(0);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.shogun-prominent-toggle:disabled {
|
|
470
|
+
opacity: 0.5;
|
|
471
|
+
cursor: not-allowed;
|
|
472
|
+
pointer-events: none;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.shogun-prominent-toggle:focus {
|
|
476
|
+
outline: 2px solid var(--shogun-primary);
|
|
477
|
+
outline-offset: 2px;
|
|
452
478
|
}
|
|
453
479
|
|
|
454
480
|
/* Redundant dark theme styles removed */
|