Created the server authentication action
This commit is contained in:
parent
9ba9fd3920
commit
110ba1b138
20
socket/actions.js
Normal file
20
socket/actions.js
Normal file
@ -0,0 +1,20 @@
|
||||
const {getServerByToken} = require("../controller/link");
|
||||
|
||||
// Authenticates the server by a token
|
||||
module.exports.authenticateServer = async (client, data) => {
|
||||
if (!data.token) return;
|
||||
|
||||
const server = await getServerByToken(data.token);
|
||||
if (!server) {
|
||||
client.send(JSON.stringify({code: 2, message: "Authentication failed"}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!server.linked)
|
||||
await server.updateOne({linked: true}).exec();
|
||||
|
||||
if (!server.online)
|
||||
await server.updateOne({online: true}).exec();
|
||||
|
||||
return server;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user