signinwith 1.0.7 → 1.0.9
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 +18 -2
- package/package.json +4 -2
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export const verifySigninGoogle = async (config, verificationData) => {
|
|
|
5
5
|
return payload.email ? { success: true, email: payload.email } : { success: false, error: 'Email not found' };
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const verifySigninFacebook = async (config, verificationData) => {
|
|
9
9
|
const res = await fetch(`https://graph.facebook.com/me?fields=email&access_token=${verificationData.accessToken}`);
|
|
10
10
|
const profile = await res.json();
|
|
11
11
|
return profile.email ? { success: true, email: profile.email } : { success: false, error: 'Email not available from Facebook' };
|
|
@@ -25,6 +25,22 @@ export const verifySigninApple = async (config, verificationData) => {
|
|
|
25
25
|
return result.email ? { success: true, email: result.email } : { success: false, error: 'Email not available from Apple' };
|
|
26
26
|
};
|
|
27
27
|
export const verifySigninDiscord = async (config, verificationData) => {
|
|
28
|
+
const tokenResponse = await fetch('https://discord.com/api/v10/oauth2/token', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
32
|
+
},
|
|
33
|
+
body: new URLSearchParams({
|
|
34
|
+
client_id: config.clientId,
|
|
35
|
+
client_secret: config.clientSecret,
|
|
36
|
+
code: verificationData.code,
|
|
37
|
+
grant_type: 'authorization_code',
|
|
38
|
+
redirect_uri: config.redirectUri,
|
|
39
|
+
scope: 'identity email',
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
const token = await tokenResponse.json();
|
|
43
|
+
verificationData.accessToken = token.access_token;
|
|
28
44
|
const res = await fetch('https://discord.com/api/v10/users/@me', {
|
|
29
45
|
headers: {
|
|
30
46
|
authorization: `Bearer ${verificationData.accessToken}`,
|
|
@@ -37,7 +53,7 @@ export const verifySigninDiscord = async (config, verificationData) => {
|
|
|
37
53
|
export default async function verifySignin (services, service, verificationData) {
|
|
38
54
|
try {
|
|
39
55
|
if (services.google && service === 'google') return await verifySigninGoogle(services.google, verificationData);
|
|
40
|
-
if (services.facebook && service === 'facebook') return await
|
|
56
|
+
if (services.facebook && service === 'facebook') return await verifySigninFacebook(services.facebook, verificationData);
|
|
41
57
|
if (services.apple && service === 'apple') return await verifySigninApple(services.apple, verificationData);
|
|
42
58
|
if (services.discord && service === 'discord') return await verifySigninDiscord(services.discord, verificationData);
|
|
43
59
|
return { success: false, error: 'Unsupported service' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signinwith",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Simple and straightforward library for sign in / sign up with thirdparty oAuth services like Google, Meta, Apple, Discord...",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"author": "ybouane",
|
|
30
30
|
"license": "ISC",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^18"
|
|
33
35
|
}
|
|
34
36
|
}
|