forked from microauth/microauth-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
32 lines (23 loc) · 688 Bytes
/
example.js
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
28
29
30
31
32
const { send } = require('micro');
const microAuthSlack = require('./index');
const options = {
clientId: 'CLIENT_ID',
clientSecret: 'CLIENT_SECRET',
callbackUrl: 'https://localhost:3000/auth/slack/callback',
path: '/auth/slack',
scope: 'identity.basic,identity.team,identity.avatar'
};
const slackAuth = microAuthSlack(options);
const handler = 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');
}
// Save something in database here
return `Hello ${auth.result.info.user.name}`;
};
module.exports = slackAuth(handler);