-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.js
More file actions
27 lines (22 loc) · 831 Bytes
/
example.js
File metadata and controls
27 lines (22 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { send } = require('micro');
const microAuthFacebook = require('.');
const options = {
appId: 'APP_ID',
appSecret: 'APP_SECRET',
callbackUrl: 'http://localhost:3000/auth/facebook/callback',
path: '/auth/facebook',
fields: 'name,email,cover,first_name', // Check fields list here: https://developers.facebook.com/docs/graph-api/reference/v2.11/user
scope: 'public_profile,email' // Check permissions list here: https://developers.facebook.com/docs/facebook-login/permissions
};
const facebookAuth = microAuthFacebook(options);
module.exports = facebookAuth(async (req, res, auth) => {
if (!auth) {
return send(res, 404, 'Not Found');
}
if (auth.err) {
// Error handler
console.error(auth.err);
return send(res, 403, 'Forbidden');
}
return `Hello ${auth.result.info.first_name}`;
});