Change LoginHandler response to always use JSON, add token-grabber.js example for interacting with the login API.
This commit is contained in:
parent
e03a902680
commit
bf1c71f176
3 changed files with 46 additions and 9 deletions
23
docs/examples/token-grabber.js
Normal file
23
docs/examples/token-grabber.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import readline from 'readline/promises';
|
||||
import { stdin as input, stdout as output } from 'process';
|
||||
|
||||
const rl = readline.createInterface({ input, output });
|
||||
|
||||
const username = await rl.question('Please enter your username: ');
|
||||
const password = await rl.question('Please enter your password: ');
|
||||
|
||||
rl.close();
|
||||
|
||||
const loginResponse = await fetch('http://localhost:8080/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await loginResponse.json();
|
||||
if (data.success != 'true') {
|
||||
console.log(`Login not successful: ${data.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const sessionID = data.sessionId;
|
||||
console.log(`Your token is: ${sessionID}`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue