react-es-fb-login 1.0.5 → 1.0.6
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/facebook-login.client.d.ts +16 -0
- package/dist/facebook-login.client.js +104 -0
- package/dist/facebook-login.d.ts +4 -0
- package/dist/facebook-login.js +94 -0
- package/dist/helpers/dom.helper.d.ts +1 -0
- package/dist/helpers/dom.helper.js +30 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/helpers/param.helper.d.ts +5 -0
- package/dist/helpers/param.helper.js +27 -0
- package/dist/helpers/ua.helper.d.ts +1 -0
- package/dist/helpers/ua.helper.js +13 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +25 -0
- package/dist/types/fb.type.d.ts +11 -0
- package/dist/types/fb.type.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/params.type.d.ts +119 -0
- package/dist/types/params.type.js +2 -0
- package/dist/types/response.type.d.ts +49 -0
- package/dist/types/response.type.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DialogParams, InitParams, LoginOptions, LoginResponse } from './types';
|
|
2
|
+
export declare const SDK_SCRIPT_ELE_ID = "facebook-jssdk";
|
|
3
|
+
export declare const FacebookLoginClient: {
|
|
4
|
+
getFB: () => import("./types").FB;
|
|
5
|
+
getLoginStatus(callback: (res: LoginResponse) => void, isForcingRoudtrip?: boolean): void;
|
|
6
|
+
getProfile(callback: (res: unknown) => void, params: {
|
|
7
|
+
fields: string;
|
|
8
|
+
}): void;
|
|
9
|
+
init(initParams: InitParams): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
isRedirected(dialogParams?: DialogParams): boolean;
|
|
12
|
+
loadSdk(language: string, useCustomerChat?: boolean): Promise<void>;
|
|
13
|
+
redirectToDialog(dialogParams: DialogParams, { ignoreSdkError, ...loginOptions }: LoginOptions): void;
|
|
14
|
+
login(callback: (res: LoginResponse) => void, { ignoreSdkError, ...loginOptions }: LoginOptions): void;
|
|
15
|
+
logout(callback: (res?: unknown) => void): void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.FacebookLoginClient = exports.SDK_SCRIPT_ELE_ID = void 0;
|
|
24
|
+
const helpers_1 = require("./helpers");
|
|
25
|
+
exports.SDK_SCRIPT_ELE_ID = 'facebook-jssdk';
|
|
26
|
+
exports.FacebookLoginClient = {
|
|
27
|
+
getFB: () => {
|
|
28
|
+
if (!window.FB) {
|
|
29
|
+
console.warn('FB not found');
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return window.FB;
|
|
33
|
+
},
|
|
34
|
+
getLoginStatus(callback, isForcingRoudtrip = false) {
|
|
35
|
+
const FB = this.getFB();
|
|
36
|
+
if (!FB) {
|
|
37
|
+
callback({ status: 'unknown' });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
FB.getLoginStatus(callback, isForcingRoudtrip);
|
|
41
|
+
},
|
|
42
|
+
getProfile(callback, params) {
|
|
43
|
+
var _a;
|
|
44
|
+
(_a = this.getFB()) === null || _a === void 0 ? void 0 : _a.api('me', params, callback);
|
|
45
|
+
},
|
|
46
|
+
init(initParams) {
|
|
47
|
+
var _a;
|
|
48
|
+
(_a = this.getFB()) === null || _a === void 0 ? void 0 : _a.init(initParams);
|
|
49
|
+
},
|
|
50
|
+
clear() {
|
|
51
|
+
window.FB = null;
|
|
52
|
+
const scriptEle = document.getElementById(exports.SDK_SCRIPT_ELE_ID);
|
|
53
|
+
if (scriptEle) {
|
|
54
|
+
scriptEle.remove();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
isRedirected(dialogParams) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const params = (0, helpers_1.paramsToObject)(window.location.search);
|
|
60
|
+
return ((params['state'] === ((_a = dialogParams === null || dialogParams === void 0 ? void 0 : dialogParams.state) !== null && _a !== void 0 ? _a : 'facebookdirect')) &&
|
|
61
|
+
params[(_b = dialogParams === null || dialogParams === void 0 ? void 0 : dialogParams.response_type) !== null && _b !== void 0 ? _b : ''] !== undefined);
|
|
62
|
+
},
|
|
63
|
+
loadSdk(language, useCustomerChat) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield (0, helpers_1.createScriptEle)(exports.SDK_SCRIPT_ELE_ID, `https://connect.facebook.net/${language}/sdk${useCustomerChat ? '/xfbml.customerchat' : ''}.js`);
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
redirectToDialog(dialogParams,
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
+
_a) {
|
|
71
|
+
var
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
73
|
+
{ ignoreSdkError } = _a, loginOptions = __rest(_a,
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
+
["ignoreSdkError"]);
|
|
76
|
+
window.location.href = `https://www.facebook.com/dialog/oauth${(0, helpers_1.objectToParams)(Object.assign(Object.assign({}, dialogParams), loginOptions))}`;
|
|
77
|
+
},
|
|
78
|
+
login(callback, _a) {
|
|
79
|
+
var _b;
|
|
80
|
+
var { ignoreSdkError } = _a, loginOptions = __rest(_a, ["ignoreSdkError"]);
|
|
81
|
+
try {
|
|
82
|
+
(_b = this.getFB()) === null || _b === void 0 ? void 0 : _b.login(callback, loginOptions);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (ignoreSdkError) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
logout(callback) {
|
|
94
|
+
this.getLoginStatus((res) => {
|
|
95
|
+
var _a;
|
|
96
|
+
if (res.status === 'connected') {
|
|
97
|
+
(_a = this.getFB()) === null || _a === void 0 ? void 0 : _a.logout(callback);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
callback();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const react_1 = __importStar(require("react"));
|
|
36
|
+
const facebook_login_client_1 = require("./facebook-login.client");
|
|
37
|
+
const helpers_1 = require("./helpers");
|
|
38
|
+
const FacebookLogin = (props) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const { appId, style, onFail, render, onSuccess, className, autoLoad = false, onProfileSuccess, language = 'en_US', useRedirect = false, useCustomerChat = false, fields = 'name,email,picture', scope = 'public_profile, email', children = 'Login with Facebook', } = props;
|
|
41
|
+
const initParams = Object.assign(Object.assign({ version: 'v17.0', xfbml: false, cookie: false, localStorage: true }, props.initParams), { appId });
|
|
42
|
+
const dialogParams = Object.assign(Object.assign({ redirect_uri: typeof window !== 'undefined' ? location.origin + location.pathname : '/', state: 'facebookdirect', response_type: 'code' }, props.dialogParams), { client_id: appId });
|
|
43
|
+
const loginOptions = Object.assign(Object.assign({ return_scopes: false, ignoreSdkError: false }, props.loginOptions), { auth_nonce: typeof ((_a = props.loginOptions) === null || _a === void 0 ? void 0 : _a.auth_nonce) === 'function'
|
|
44
|
+
? props.loginOptions.auth_nonce()
|
|
45
|
+
: (_b = props.loginOptions) === null || _b === void 0 ? void 0 : _b.auth_nonce, scope });
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
init();
|
|
48
|
+
}, []);
|
|
49
|
+
const init = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
yield facebook_login_client_1.FacebookLoginClient.loadSdk(language, useCustomerChat);
|
|
51
|
+
window.fbAsyncInit = () => {
|
|
52
|
+
facebook_login_client_1.FacebookLoginClient.init(initParams);
|
|
53
|
+
const isRedirected = facebook_login_client_1.FacebookLoginClient.isRedirected(dialogParams);
|
|
54
|
+
if (isRedirected === false && autoLoad) {
|
|
55
|
+
handleButtonClick();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (isRedirected === true && useRedirect) {
|
|
59
|
+
requestLogin();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const requestLogin = () => {
|
|
64
|
+
facebook_login_client_1.FacebookLoginClient.login((res) => {
|
|
65
|
+
if (!res.authResponse) {
|
|
66
|
+
onFail && onFail({ status: 'loginCancelled' });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
onSuccess && onSuccess(res.authResponse);
|
|
70
|
+
if (onProfileSuccess) {
|
|
71
|
+
facebook_login_client_1.FacebookLoginClient.getProfile(onProfileSuccess, { fields });
|
|
72
|
+
}
|
|
73
|
+
}, Object.assign(Object.assign({}, loginOptions), { scope }));
|
|
74
|
+
};
|
|
75
|
+
const handleButtonClick = () => {
|
|
76
|
+
if ((0, helpers_1.isFacebookApp)() || useRedirect) {
|
|
77
|
+
facebook_login_client_1.FacebookLoginClient.redirectToDialog(dialogParams, loginOptions);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!window.FB) {
|
|
81
|
+
onFail && onFail({ status: 'facebookNotLoaded' });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
requestLogin();
|
|
85
|
+
};
|
|
86
|
+
if (render) {
|
|
87
|
+
return render({
|
|
88
|
+
onClick: handleButtonClick,
|
|
89
|
+
logout: facebook_login_client_1.FacebookLoginClient.logout,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return (react_1.default.createElement("button", { type: "button", style: style, className: className, onClick: handleButtonClick }, children));
|
|
93
|
+
};
|
|
94
|
+
exports.default = FacebookLogin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createScriptEle: (id: string, src: string) => Promise<unknown>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createScriptEle = void 0;
|
|
4
|
+
const createScriptEle = (id, src) => {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const element = document.getElementsByTagName('script')[0];
|
|
8
|
+
const fjs = element;
|
|
9
|
+
// return if script already exists
|
|
10
|
+
if (document.getElementById(id)) {
|
|
11
|
+
resolve(undefined);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const js = document.createElement('script');
|
|
15
|
+
js.id = id;
|
|
16
|
+
js.src = src;
|
|
17
|
+
js.async = true;
|
|
18
|
+
js.defer = true;
|
|
19
|
+
js.crossOrigin = 'anonymous';
|
|
20
|
+
js.onload = resolve;
|
|
21
|
+
if (fjs) {
|
|
22
|
+
(_a = fjs.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(js, fjs);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const children = document.body.childNodes;
|
|
26
|
+
document.body.insertBefore(js, children.item(children.length - 1));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.createScriptEle = createScriptEle;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dom.helper"), exports);
|
|
18
|
+
__exportStar(require("./param.helper"), exports);
|
|
19
|
+
__exportStar(require("./ua.helper"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const isObject: (obj: unknown) => obj is Record<string, string | number | boolean>;
|
|
2
|
+
/** Encode object to url parameters */
|
|
3
|
+
export declare const objectToParams: (obj: unknown) => string;
|
|
4
|
+
/** Decode params to object */
|
|
5
|
+
export declare const paramsToObject: (params: string) => Record<string, string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paramsToObject = exports.objectToParams = exports.isObject = void 0;
|
|
4
|
+
const isObject = (obj) => {
|
|
5
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
6
|
+
};
|
|
7
|
+
exports.isObject = isObject;
|
|
8
|
+
/** Encode object to url parameters */
|
|
9
|
+
const objectToParams = (obj) => {
|
|
10
|
+
if (!(0, exports.isObject)(obj) || Object.keys(obj).length === 0) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
return ('?' +
|
|
14
|
+
Object.keys(obj)
|
|
15
|
+
.map((key) => `${key}=${encodeURIComponent(obj[key])}`)
|
|
16
|
+
.join('&'));
|
|
17
|
+
};
|
|
18
|
+
exports.objectToParams = objectToParams;
|
|
19
|
+
/** Decode params to object */
|
|
20
|
+
const paramsToObject = (params) => (params === null || params === void 0 ? void 0 : params.replace(/^\?/, '').split('&').reduce((acc, chunk) => {
|
|
21
|
+
if (!chunk) {
|
|
22
|
+
return acc;
|
|
23
|
+
}
|
|
24
|
+
const [key, value] = chunk.split('=');
|
|
25
|
+
return Object.assign(Object.assign({}, acc), { [key]: decodeURIComponent(value) });
|
|
26
|
+
}, {})) || {};
|
|
27
|
+
exports.paramsToObject = paramsToObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isFacebookApp: () => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFacebookApp = void 0;
|
|
4
|
+
const isFacebookApp = () => {
|
|
5
|
+
if (typeof window === 'undefined') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const ua = navigator.userAgent || navigator.vendor || window.opera;
|
|
9
|
+
return (ua.indexOf('FBAN') > -1 ||
|
|
10
|
+
ua.indexOf('FBAV') > -1 ||
|
|
11
|
+
ua.indexOf('Instagram') > -1);
|
|
12
|
+
};
|
|
13
|
+
exports.isFacebookApp = isFacebookApp;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const facebook_login_1 = __importDefault(require("./facebook-login"));
|
|
21
|
+
__exportStar(require("./helpers"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./facebook-login"), exports);
|
|
24
|
+
__exportStar(require("./facebook-login.client"), exports);
|
|
25
|
+
exports.default = facebook_login_1.default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InitParams, LoginOptions } from './params.type';
|
|
2
|
+
import { LoginResponse } from './response.type';
|
|
3
|
+
export interface FB {
|
|
4
|
+
getLoginStatus: (callback: (res: LoginResponse) => void, isForcingRoudtrip?: boolean) => void;
|
|
5
|
+
init: (params: InitParams) => void;
|
|
6
|
+
login: (callback: (res: LoginResponse) => void, options?: LoginOptions) => void;
|
|
7
|
+
logout: (callback: (res: unknown) => void) => void;
|
|
8
|
+
api: (path: string, params: {
|
|
9
|
+
fields: string;
|
|
10
|
+
}, callback: (res: unknown) => void) => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fb.type"), exports);
|
|
18
|
+
__exportStar(require("./params.type"), exports);
|
|
19
|
+
__exportStar(require("./response.type"), exports);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { CSSProperties, ReactElement, ReactNode, ReactNodeArray } from 'react';
|
|
2
|
+
import { FB } from './fb.type';
|
|
3
|
+
import { SuccessResponse, FailResponse, ProfileSuccessResponse } from './response.type';
|
|
4
|
+
export type InitParams = {
|
|
5
|
+
/** Your application ID. */
|
|
6
|
+
appId: string;
|
|
7
|
+
/** Determines which versions of the Graph API and any API dialogs or plugins are invoked
|
|
8
|
+
*
|
|
9
|
+
* (available versions: https://developers.facebook.com/docs/graph-api/changelog)
|
|
10
|
+
* @default 'v9.0' */
|
|
11
|
+
version?: 'v7.0' | 'v8.0' | 'v9.0' | 'v10.0' | 'v11.0' | 'v12.0' | 'v13.0' | 'v14.0' | 'v15.0' | 'v16.0' | 'v17.0' | 'v18.0' | 'v19.0' | 'v20.0' | 'v21.0' | 'v22.0' | 'v23.0' | 'v24.0' | 'v25.0' | 'v26.0' | 'v27.0' | 'v28.0' | 'v29.0' | 'v30.0' | 'v31.0' | 'v32.0' | 'v33.0' | 'v34.0' | 'v35.0' | 'v36.0';
|
|
12
|
+
/** Determines whether a cookie is created for the session or not. If enabled, it can be accessed by server-side code.
|
|
13
|
+
* @default false */
|
|
14
|
+
cookie?: boolean;
|
|
15
|
+
/** Determines whether a long-lived access token for the session can be saved in localStorage. This enables maintaining a user's logged in status when 3rd party cookies are blocked from being sent to Facebook domains.
|
|
16
|
+
* @default true */
|
|
17
|
+
localStorage?: boolean;
|
|
18
|
+
/** Determines whether XFBML tags used by social plugins are parsed, and therefore whether the plugins are rendered or not.
|
|
19
|
+
* @default false */
|
|
20
|
+
xfbml?: boolean;
|
|
21
|
+
/** Frictionless Requests are available to games on Facebook.com or on mobile web using the JavaScript SDK. This parameter determines whether they are enabled.
|
|
22
|
+
* @default false */
|
|
23
|
+
frictionlessRequests?: boolean;
|
|
24
|
+
/** This specifies a function that is called whenever it is necessary to hide Adobe Flash objects on a page. This is used when .api() requests are made, as Flash objects will always have a higher z-index than any other DOM element.
|
|
25
|
+
*
|
|
26
|
+
* @link https://developers.facebook.com/docs/games/gamesonfacebook/optimizing#handlingpopups */
|
|
27
|
+
hideFlashCallback?: () => void;
|
|
28
|
+
};
|
|
29
|
+
export type DialogParams = {
|
|
30
|
+
/** same as appId */
|
|
31
|
+
client_id: string;
|
|
32
|
+
/** The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html. You can confirm that this URL is set for your app in the App Dashboard. Under Products in the App Dashboard's left side navigation menu, click Facebook Login, then click Settings. Verify the Valid OAuth redirect URIs in the Client OAuth Settings section.
|
|
33
|
+
* @default (typeof window !== 'undefined' ? location.origin + location.pathname : '/') */
|
|
34
|
+
redirect_uri: string;
|
|
35
|
+
/** A string value created by your app to maintain state between the request and callback. This parameter should be used for preventing Cross-site Request Forgery and will be passed back to you, unchanged, in your redirect URI.
|
|
36
|
+
* @default 'facebookdirect' */
|
|
37
|
+
state: string;
|
|
38
|
+
/** Determines whether the response data included when the redirect back to the app occurs is in URL parameters or fragments.
|
|
39
|
+
*
|
|
40
|
+
* This can be one of ('code', 'token', 'code%20token', 'grated_scopes')
|
|
41
|
+
* @default 'code' */
|
|
42
|
+
response_type?: string;
|
|
43
|
+
/** Comma seperated list of permissions to request during login.
|
|
44
|
+
*
|
|
45
|
+
* (available permissions: https://developers.facebook.com/docs/permissions/reference)
|
|
46
|
+
* @default 'public_profile, email' */
|
|
47
|
+
scope?: string;
|
|
48
|
+
};
|
|
49
|
+
export type LoginOptions = {
|
|
50
|
+
/** supports 3 values: rerequest, reauthenticate, reauthorize.
|
|
51
|
+
*
|
|
52
|
+
* Use 'rerequest' when re-requesting a declined permission. */
|
|
53
|
+
auth_type?: 'rerequest' | 'reauthenticate' | 'reauthorize';
|
|
54
|
+
response_type?: string;
|
|
55
|
+
scope: string;
|
|
56
|
+
/** Facebook login for business uses config_id instead of scope - won't work without this - reference: https://developers.facebook.com/docs/facebook-login/facebook-login-for-business/ */
|
|
57
|
+
config_id?: string;
|
|
58
|
+
/** When true, the granted scopes will be returned in a comma-separated list in the grantedScopes field of the authResponse
|
|
59
|
+
* @default false */
|
|
60
|
+
return_scopes?: boolean;
|
|
61
|
+
override_default_response_type?: boolean;
|
|
62
|
+
/** When true, prompt the user to grant permission for one or more Pages */
|
|
63
|
+
enable_profile_selector?: boolean;
|
|
64
|
+
/** Comma separated list of IDs to display in the profile selector */
|
|
65
|
+
profile_selector_ids?: string;
|
|
66
|
+
/** The auth_nonce parameter is intended to be a completely arbitrary alphanumeric code that your app generates. The process of generation and format of this code is entirely up to you. For example, a hashed version of a timestamp and a secret string may be sufficient, as long as it's completely unique to each Login attempt. This value enables your app to determine whether a user has been re-authenticated. */
|
|
67
|
+
auth_nonce?: string | (() => string);
|
|
68
|
+
/** When true, errors catched for window.FB.login() will be ignored
|
|
69
|
+
* @default false */
|
|
70
|
+
ignoreSdkError?: boolean;
|
|
71
|
+
extras?: {
|
|
72
|
+
version?: 'v1' | 'v2' | 'v3' | 'v4' | 'v5';
|
|
73
|
+
featureType?: string;
|
|
74
|
+
features?: {
|
|
75
|
+
name: string;
|
|
76
|
+
}[];
|
|
77
|
+
setup?: unknown;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type FacebookLoginProps = Pick<InitParams, 'appId'> & {
|
|
81
|
+
/** @default 'en_US' */
|
|
82
|
+
language?: string;
|
|
83
|
+
/** Comma seperated list of permissions to request during login.
|
|
84
|
+
*
|
|
85
|
+
* (available permissions: https://developers.facebook.com/docs/permissions/reference)
|
|
86
|
+
* @default 'public_profile, email' */
|
|
87
|
+
scope?: string;
|
|
88
|
+
/** fields return by /me (profile)
|
|
89
|
+
* @default 'name,email,picture' */
|
|
90
|
+
fields?: string;
|
|
91
|
+
onSuccess?: (res: SuccessResponse) => void;
|
|
92
|
+
onFail?: (err: FailResponse) => void;
|
|
93
|
+
onProfileSuccess?: (res: ProfileSuccessResponse) => void;
|
|
94
|
+
className?: string;
|
|
95
|
+
style?: CSSProperties;
|
|
96
|
+
/** Children Component
|
|
97
|
+
* @default "Login with Facebook" */
|
|
98
|
+
children?: ReactNode | ReactNodeArray;
|
|
99
|
+
/** render custom component */
|
|
100
|
+
render?: (props: {
|
|
101
|
+
onClick?: () => void;
|
|
102
|
+
logout?: FB['logout'];
|
|
103
|
+
}) => ReactElement;
|
|
104
|
+
/** if true, request login on mount
|
|
105
|
+
* @default false */
|
|
106
|
+
autoLoad?: boolean;
|
|
107
|
+
/** if true, use redirect instead of window.FB.login
|
|
108
|
+
*
|
|
109
|
+
* forced to be true in fb browers
|
|
110
|
+
* @ref https://github.com/greatSumini/react-facebook-login/issues/2
|
|
111
|
+
* @default false */
|
|
112
|
+
useRedirect?: boolean;
|
|
113
|
+
/** if true, append 'xfbml.customerchat' to sdk url (ex: 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js')
|
|
114
|
+
* @default false */
|
|
115
|
+
useCustomerChat?: boolean;
|
|
116
|
+
initParams?: Omit<InitParams, 'appId'>;
|
|
117
|
+
loginOptions?: Omit<LoginOptions, 'scope'>;
|
|
118
|
+
dialogParams?: Pick<DialogParams, 'redirect_uri' | 'response_type' | 'state'>;
|
|
119
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare enum LoginStatus {
|
|
2
|
+
Connected = "connected",
|
|
3
|
+
NotAuthorized = "not_authorized",
|
|
4
|
+
Unknown = "unknown"
|
|
5
|
+
}
|
|
6
|
+
export type LoginResponse = {
|
|
7
|
+
status: LoginStatus;
|
|
8
|
+
authResponse?: SuccessResponse;
|
|
9
|
+
};
|
|
10
|
+
export type SuccessResponse = {
|
|
11
|
+
/** An access token for the person using the webpage. */
|
|
12
|
+
accessToken: string;
|
|
13
|
+
/**
|
|
14
|
+
* A UNIX time stamp when the token expires. Once the token expires, the person will need to login again.
|
|
15
|
+
*/
|
|
16
|
+
expiresIn: string;
|
|
17
|
+
/**
|
|
18
|
+
* The amount of time before the login expires, in seconds, and the person will need to login again.
|
|
19
|
+
*/
|
|
20
|
+
reauthorize_required_in: string;
|
|
21
|
+
/**
|
|
22
|
+
* A signed parameter that contains information about the person using your webpage.
|
|
23
|
+
*/
|
|
24
|
+
signedRequest: string;
|
|
25
|
+
/** The ID of the person using your webpage. */
|
|
26
|
+
userID: string;
|
|
27
|
+
};
|
|
28
|
+
export type FailResponse = {
|
|
29
|
+
status: 'loginCancelled' | 'facebookNotLoaded';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Response from /me endpoint. These values will vary depending on provided fields param.
|
|
33
|
+
*
|
|
34
|
+
* @see https://developers.facebook.com/docs/graph-api/reference/user/
|
|
35
|
+
*/
|
|
36
|
+
export type ProfileSuccessResponse = {
|
|
37
|
+
id?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
picture?: {
|
|
41
|
+
data: {
|
|
42
|
+
height: number;
|
|
43
|
+
width: string;
|
|
44
|
+
is_silhouette: boolean;
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoginStatus = void 0;
|
|
4
|
+
var LoginStatus;
|
|
5
|
+
(function (LoginStatus) {
|
|
6
|
+
LoginStatus["Connected"] = "connected";
|
|
7
|
+
LoginStatus["NotAuthorized"] = "not_authorized";
|
|
8
|
+
LoginStatus["Unknown"] = "unknown";
|
|
9
|
+
})(LoginStatus || (exports.LoginStatus = LoginStatus = {}));
|