signinwith 1.1.0 → 1.1.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/index.js +1 -1
- package/package.json +1 -1
- package/react.jsx +33 -50
- package/readme.md +1 -1
package/index.js
CHANGED
|
@@ -79,7 +79,7 @@ export const verifySigninGithub = async (config, verificationData) => {
|
|
|
79
79
|
const apiHeaders = {
|
|
80
80
|
'Authorization': `Bearer ${accessToken}`,
|
|
81
81
|
'Accept': 'application/vnd.github+json',
|
|
82
|
-
'User-Agent':
|
|
82
|
+
'User-Agent': 'signinwith',
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
const profileRes = await fetch('https://api.github.com/user', { headers: apiHeaders });
|
package/package.json
CHANGED
package/react.jsx
CHANGED
|
@@ -68,69 +68,52 @@ export function SignInWithFacebook({ service, onSignin, onError }) {
|
|
|
68
68
|
|
|
69
69
|
// Subcomponent: Google
|
|
70
70
|
export function SignInWithGoogle({ service, onSignin, onError }) {
|
|
71
|
+
const codeClientRef = useRef(null);
|
|
72
|
+
|
|
71
73
|
useEffect(() => {
|
|
72
|
-
const scriptId =
|
|
74
|
+
const scriptId = "google-gsi-script";
|
|
73
75
|
let script = document.getElementById(scriptId);
|
|
74
76
|
|
|
77
|
+
const init = () => {
|
|
78
|
+
if (!window.google?.accounts?.oauth2) {
|
|
79
|
+
onError?.("Google OAuth library not available.");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
codeClientRef.current = window.google.accounts.oauth2.initCodeClient({
|
|
84
|
+
client_id: service.clientId,
|
|
85
|
+
scope: "openid email profile",
|
|
86
|
+
ux_mode: "popup",
|
|
87
|
+
callback: (res) => {
|
|
88
|
+
// res.code is the authorization code (send to backend)
|
|
89
|
+
if (!res?.code) return onError?.("No auth code received from Google.");
|
|
90
|
+
onSignin("google", { code: res.code });
|
|
91
|
+
},
|
|
92
|
+
error_callback: (err) => {
|
|
93
|
+
onError?.(err?.message || "Google sign-in failed.");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
75
98
|
if (!script) {
|
|
76
|
-
script = document.createElement(
|
|
99
|
+
script = document.createElement("script");
|
|
77
100
|
script.id = scriptId;
|
|
78
|
-
script.src =
|
|
101
|
+
script.src = "https://accounts.google.com/gsi/client";
|
|
79
102
|
script.async = true;
|
|
80
103
|
script.defer = true;
|
|
81
|
-
script.onload =
|
|
82
|
-
|
|
83
|
-
window.google.accounts.id.initialize({
|
|
84
|
-
client_id: service.clientId,
|
|
85
|
-
use_fedcm_for_prompt: true,
|
|
86
|
-
callback: (res) => {
|
|
87
|
-
onSignin('google', { credential: res.credential });
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
onError?.('Google Sign-In script loaded but initialization failed.');
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
script.onerror = () => {
|
|
95
|
-
onError?.('Failed to load Google Sign-In script.');
|
|
96
|
-
};
|
|
104
|
+
script.onload = init;
|
|
105
|
+
script.onerror = () => onError?.("Failed to load Google script.");
|
|
97
106
|
document.body.appendChild(script);
|
|
98
|
-
} else
|
|
99
|
-
|
|
100
|
-
window.google.accounts.id.initialize({
|
|
101
|
-
client_id: service.clientId,
|
|
102
|
-
use_fedcm_for_prompt: true,
|
|
103
|
-
callback: (res) => {
|
|
104
|
-
onSignin('google', { credential: res.credential });
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
+
} else {
|
|
108
|
+
init();
|
|
107
109
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Cleanup function does not remove the script to allow multiple instances
|
|
111
|
-
// or remounts without reloading. Google's script handles this internally.
|
|
112
|
-
return () => {
|
|
113
|
-
// Optional: You might want to hide the prompt if the component unmounts
|
|
114
|
-
// window.google?.accounts?.id?.cancel();
|
|
115
|
-
};
|
|
116
110
|
}, [service.clientId, onSignin, onError]);
|
|
117
111
|
|
|
118
112
|
const handleGoogleLogin = (e) => {
|
|
119
|
-
e.stopPropagation();
|
|
120
113
|
e.preventDefault();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
|
125
|
-
// Potentially trigger a backup UX or just log
|
|
126
|
-
onError?.(notification.getNotDisplayedReason() || notification.getSkippedReason() || 'Google Sign-In prompt was not displayed or was skipped.');
|
|
127
|
-
} else if (notification.isDismissedMoment()) {
|
|
128
|
-
onError?.(notification.getDismissedReason() || 'Google Sign-In prompt was dismissed.');
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
onError?.('Google Sign-In is not initialized.');
|
|
133
|
-
}
|
|
114
|
+
e.stopPropagation();
|
|
115
|
+
if (!codeClientRef.current) return onError?.("Google not initialized yet.");
|
|
116
|
+
codeClientRef.current.requestCode();
|
|
134
117
|
};
|
|
135
118
|
|
|
136
119
|
return (
|
package/readme.md
CHANGED
|
@@ -125,7 +125,6 @@ const servicesConfig = {
|
|
|
125
125
|
clientId: process.env.GITHUB_CLIENT_ID,
|
|
126
126
|
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
127
127
|
redirectUri: process.env.GITHUB_REDIRECT_URI,
|
|
128
|
-
userAgent: 'your-app-name',
|
|
129
128
|
},
|
|
130
129
|
};
|
|
131
130
|
|
|
@@ -180,6 +179,7 @@ The buttons have the base class `signinwith-button` and provider-specific classe
|
|
|
180
179
|
* `signinwith-button-facebook`
|
|
181
180
|
* `signinwith-button-apple`
|
|
182
181
|
* `signinwith-button-discord`
|
|
182
|
+
* `signinwith-button-github`
|
|
183
183
|
|
|
184
184
|
You can override these styles in your own CSS. The container in the example uses `signinwith-container` for layout.
|
|
185
185
|
|