Switching to ws instead of socket.io and implementing basic authentication

This commit is contained in:
Fabian
2019-10-10 12:28:44 +02:00
parent cdafa7bbd4
commit 8b6767c5f9
7 changed files with 319 additions and 416 deletions

View File

@ -1,4 +1,5 @@
import Session from "./session";
import Logging from "@hibas123/nodelogging";
interface IRule<T> {
".write"?: T
@ -64,7 +65,27 @@ export class Rules {
let rules = this.rules;
for (let segment of path) {
rules = rules[segment] || rules["*"];
if (segment.startsWith("$") || segment.startsWith(".")) {
read = false;
write = false;
Logging.log("Invalid query path (started with '$' or '.'):", path);
break;
}
let k = Object.keys(rules)
.filter(e => e.startsWith("$"))
.find(e => {
switch (e) {
case "$uid":
if (segment === session.uid)
return true;
break;
}
return false;
})
rules = (k ? rules[k] : undefined) || rules[segment] || rules["*"];
if (rules) {
if (rules[".read"]) {
read = rules[".read"]