feat(chat): added base for chat service

added front html

nigel in the mud

route function with openapi - gen

clean up the code a little

after pull request
This commit is contained in:
NigeParis 2025-11-11 10:02:05 +01:00 committed by Maix0
parent 73a4946d17
commit 9ce9fa44e4
122 changed files with 9354 additions and 2615 deletions

View file

@ -1,6 +1,6 @@
<!DOCTYPE HTML>
<html>
<!--
<head>
<title>Demo Page For Login :)</title>
</head>
@ -34,6 +34,6 @@
</div>
<pre id="d-response"></pre>
<script src="./login_demo.js"> </script>
</body>
</body> -->
</html>

View file

@ -1,115 +1,4 @@
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
};
const tUsername = document.querySelector('#t-username');
const iUsername = document.querySelector('#i-username');
const iPassword = document.querySelector('#i-password');
const iOtp = document.querySelector('#i-otp');
const bOtpSend = document.querySelector('#b-otpSend');
const bLogin = document.querySelector('#b-login');
const bLoginGuest = document.querySelector('#b-login-guest');
const bLogout = document.querySelector('#b-logout');
const bSignin = document.querySelector('#b-signin');
const bWhoami = document.querySelector('#b-whoami');
const bOtpStatus = document.querySelector('#b-otpStatus');
const bOtpEnable = document.querySelector('#b-otpEnable');
const bOtpDisable = document.querySelector('#b-otpDisable');
const dResponse = document.querySelector('#d-response');
function setResponse(obj) {
const obj_str = JSON.stringify(obj, null, 4);
dResponse.innerText = obj_str;
}
let otpToken = null;
bLoginGuest.addEventListener('click', async () => {
const res = await fetch('/api/auth/guest', { method: 'POST' });
const json = await res.json();
setResponse(json);
if (json.kind === 'success') {
if (json?.payload?.token) {document.cookie = `token=${json?.payload?.token}`;}
}
});
bOtpSend.addEventListener('click', async () => {
const res = await fetch('/api/auth/otp', { method: 'POST', body: JSON.stringify({ code: iOtp.value, token: otpToken }), headers });
const json = await res.json();
setResponse(json);
if (json.kind === 'success') {
if (json?.payload?.token) {document.cookie = `token=${json?.payload?.token}`;}
}
});
bOtpStatus.addEventListener('click', async () => {
const res = await fetch('/api/auth/statusOtp');
const json = await res.json();
setResponse(json);
});
bOtpEnable.addEventListener('click', async () => {
const res = await fetch('/api/auth/enableOtp', { method: 'PUT' });
const json = await res.json();
setResponse(json);
});
bOtpDisable.addEventListener('click', async () => {
const res = await fetch('/api/auth/disableOtp', { method: 'PUT' });
const json = await res.json();
setResponse(json);
});
bWhoami.addEventListener('click', async () => {
let username = '';
try {
const res = await fetch('/api/user/info/me');
const json = await res.json();
setResponse(json);
if (json?.kind === 'success') {username = json?.payload?.name;}
else {username = `<not logged in:${json.msg}>`;}
}
catch {
username = '<not logged in: threw>';
}
tUsername.innerText = username;
});
bLogin.addEventListener('click', async () => {
const name = iUsername.value;
const password = iPassword.value;
const res = await fetch('/api/auth/login', { method: 'POST', body: JSON.stringify({ name, password }), headers });
const json = await res.json();
if (json?.kind === 'otpRequired') {
otpToken = json?.payload?.token;
}
else if (json?.kind === 'success') {
if (json?.payload?.token) {document.cookie = `token=${json?.payload?.token}`;}
}
setResponse(json);
});
bLogout.addEventListener('click', async () => {
const res = await fetch('/api/auth/logout', { method: 'POST' });
setResponse(await res.json());
});
bSignin.addEventListener('click', async () => {
const name = iUsername.value;
const password = iPassword.value;
const res = await fetch('/api/auth/signin', { method: 'POST', body: JSON.stringify({ name, password }), headers });
const json = await res.json();
if (json?.payload?.token) {document.cookie = `token=${json?.payload?.token};`;}
setResponse(json);
});
// const headers = {
// 'Accept': 'application/json',
// 'Content-Type': 'application/json',
// };

View file

@ -1,7 +1,7 @@
{
"openapi": "3.1.0",
"info": {
"version": "9.6.0",
"version": "9.6.1",
"title": "@fastify/swagger"
},
"components": {
@ -144,26 +144,50 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
"anyOf": [
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"failure"
]
},
"msg": {
"enum": [
"enableOtp.failure.noUser",
"enableOtp.failure.noSecret"
]
}
}
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
}
}
]
}
}
}
@ -782,26 +806,52 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
"anyOf": [
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
}
}
]
}
}
}

View file

@ -23,14 +23,14 @@
"@fastify/multipart": "^9.3.0",
"@fastify/sensible": "^6.0.3",
"@fastify/static": "^8.3.0",
"typebox": "^1.0.51",
"confbox": "^0.2.2",
"fastify": "^5.6.1",
"fastify": "^5.6.2",
"fastify-cli": "^7.4.1",
"fastify-plugin": "^5.1.0"
"fastify-plugin": "^5.1.0",
"typebox": "^1.0.53"
},
"devDependencies": {
"@types/node": "^22.19.0",
"@types/node": "^22.19.1",
"rollup-plugin-node-externals": "^8.1.2",
"vite": "^7.2.2",
"vite-tsconfig-paths": "^5.1.4"

View file

@ -27,6 +27,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
void req;
void res;
try {
console.log('DEBUG ----- guest login backend');
const adjective = getRandomFromList(fastify.words.adjectives);
const noun = getRandomFromList(fastify.words.nouns);