-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.js
52 lines (48 loc) · 1.33 KB
/
authentication.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const testAuth = async (z, bundle) => {
const options = {
url: 'https://api.hashnode.com',
method: 'POST',
headers: {
Authorization: bundle.authData.pat,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'query TestConnection($username: String!) { user(username: $username) { _id username name publication { _id title } }}',
variables: {
username: bundle.authData.username,
},
}),
};
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
// You can do any parsing you need for results here before returning them
return results;
});
};
module.exports = {
type: 'custom',
test: testAuth,
fields: [
{
computed: false,
key: 'pat',
required: true,
label: 'Personal Access Token',
type: 'password',
helpText:
'Enter your Hashnode Personal Access Token, found at https://hashnode.com/settings/developer',
},
{
computed: false,
key: 'username',
required: true,
label: 'Your Hashnode username',
type: 'string',
helpText:
'Enter your Hashnode username',
},
],
customConfig: {},
connectionLabel: '{{data__user__username}} - {{data__user__publication__title}} ({{data__user__publication___id}})',
};