Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 30e1be3

Browse files
authored
Update Misc.js
1 parent ca88fb6 commit 30e1be3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/classes/Misc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@ class Misc {
3838
}
3939
}
4040
}
41+
42+
async isAuthenticated() {
43+
if (!global.cookies) {
44+
throw new Error('Not logged in.');
45+
} else {
46+
headers.Cookie = global.cookies;
47+
let info = await variables
48+
.fetch('https://staging.repl.it/is_authenticated', {
49+
method: 'POST',
50+
headers,
51+
body: JSON.stringify({
52+
query: `
53+
query UserSearch($query: String!, $limit: Int!) {
54+
usernameSearch(query: $query, limit: $limit) {
55+
${variables.userAttributes}
56+
}
57+
}`,
58+
variables: {
59+
query,
60+
limit
61+
}
62+
})
63+
}).then(res => res.json());
64+
65+
if (!info.data.usernameSearch) {
66+
throw new Error(`Cannot fetch users.`);
67+
} else {
68+
return info.data.usernameSearch;
69+
}
70+
}
71+
}
4172
}
4273

4374
module.exports = {

0 commit comments

Comments
 (0)