Working auth and fixed a lot of bugs
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
import readline from 'readline';
|
||||
|
||||
async function createServerToken() {
|
||||
return (await (await fetch('http://localhost:3000/api/auth', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
intents: 'server',
|
||||
server_ip: '127.0.0.1'
|
||||
})
|
||||
})).json()).token;
|
||||
}
|
||||
|
||||
const token = await createServerToken();
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
@@ -10,11 +22,15 @@ const ws = new WebSocket('ws://localhost:7080');
|
||||
ws.onopen = () => {
|
||||
console.log('WebSocket connection established');
|
||||
console.log('Initializing handshake');
|
||||
ws.send(JSON.stringify({ version: '0.0.1', auth_token: '<placeholder>' }))
|
||||
ws.send(JSON.stringify({ version: '0.0.1', auth_token: token }))
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.type === 'authenticated') {
|
||||
console.log('Logged in with uuid: ' + message.params.messages);
|
||||
console.log(message.params.messages);
|
||||
}
|
||||
console.log('Received:', message);
|
||||
// ws.close();
|
||||
};
|
||||
@@ -34,5 +50,9 @@ function ask(question) {
|
||||
|
||||
while (true) {
|
||||
const message = await ask('');
|
||||
if (message === 'q') {
|
||||
ws.close();
|
||||
process.exit();
|
||||
}
|
||||
sendMessage(message);
|
||||
}
|
||||
Reference in New Issue
Block a user