Added guest

This commit is contained in:
Gleb Koval 2021-07-04 17:26:04 +01:00
parent af2c334e66
commit 3d99854c9d
No known key found for this signature in database
GPG Key ID: 120F2F6DA9D995FB
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,8 @@
export enum Permissions { export enum Permissions {
ALL = "*" ALL = "*",
VIEW_PROFILE = "view_profile",
ADD_PROFILE = "add_profile",
MANAGE_PERMISSIONS = "manage_permissions"
} }
/** /**

View File

@ -6,6 +6,7 @@ import * as sapper from "@sapper/server";
import arangojs, { Database, aql } from "arangojs"; import arangojs, { Database, aql } from "arangojs";
import { hash } from "bcrypt"; import { hash } from "bcrypt";
import { log } from "./logger"; import { log } from "./logger";
import { Permissions } from "./lib/permissions";
const { PORT, NODE_ENV, DB_USERNAME, DB_PASSWORD, DB_URL, DB_NAME, API_KEY } = const { PORT, NODE_ENV, DB_USERNAME, DB_PASSWORD, DB_URL, DB_NAME, API_KEY } =
process.env; process.env;
@ -33,7 +34,11 @@ const intervalFunc = async (db: Database) => {
username: DB_USERNAME, username: DB_USERNAME,
password: await hash(DB_PASSWORD || "SBDataTracker", saltRounds), password: await hash(DB_PASSWORD || "SBDataTracker", saltRounds),
forceChangePassword: true, forceChangePassword: true,
permissions: ["*"] permissions: [Permissions.ALL]
});
await users.save({
username: "_guest",
permissions: [Permissions.VIEW_PROFILE]
}); });
} }
@ -74,6 +79,9 @@ const intervalFunc = async (db: Database) => {
); );
} }
}; };
// Separated into setInterval and a setTimeout so when the script is started,
// immediately at least one profile is logged. This is useful for debugging
// since you don't have to wait for up to 3 minutes to pass.
if ((cursor.count as number) > 1) if ((cursor.count as number) > 1)
interval = setInterval( interval = setInterval(
iterate, iterate,