From 0bc7cb11f04758d9e1a63b470839b2e0f43bbc06 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Fri, 3 May 2024 09:26:12 +1000 Subject: [PATCH] Fully tested the remote database Added configurable hostname for default account email --- .envdev | 3 +++ Dockerfile | 2 +- README.md | 4 ++-- configure-script.js | 2 ++ server/admin/default-account.js | 7 +++---- tools/debug-startup.sql | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.envdev b/.envdev index 843664a..dde9c57 100644 --- a/.envdev +++ b/.envdev @@ -22,6 +22,9 @@ ADMIN_DEFAULT_USERNAME=admin # Give this a value to generate the default admin account (must be at least 8 characters) ADMIN_DEFAULT_PASSWORD=password +# Give this a value to generate teh default admin account (must be a valid domain name, to pass the initial email check) +ADMIN_DEFAULT_HOSTNAME=example.com + # Select a "TZ database name" that suits your needs: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones DB_TIMEZONE=Australia/Sydney diff --git a/Dockerfile b/Dockerfile index a2f2330..b945fde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM node:21-bookworm-slim +FROM node:22-bookworm-slim WORKDIR "/app" COPY package*.json /app RUN npm install --production diff --git a/README.md b/README.md index 965dcb4..400d3e8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This server is available via docker hub at krgamestudios/auth-server. # Setup -There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql. +There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql. # API @@ -79,7 +79,7 @@ Cookie: refreshToken ### -//DOCS: Retreives the private account data, results vary +//DOCS: Retrieves the private account data, results vary GET /auth/account Authorization: Bearer accessToken diff --git a/configure-script.js b/configure-script.js index bb9e63f..f238dcb 100644 --- a/configure-script.js +++ b/configure-script.js @@ -65,6 +65,7 @@ const question = (prompt, def = null) => { const appMailPhysical = await question('Mail Physical'); const appDefaultUser = await question('App Default User', ''); + const appDefaultHost = await question('App Default Host', ''); const appDefaultPass = await question('App Default Pass', ''); const appSecretAccess = await question('Access Token Secret', uuid(32)); @@ -105,6 +106,7 @@ services: - MAIL_PASSWORD=${appMailPass} - MAIL_PHYSICAL=${appMailPhysical} - ADMIN_DEFAULT_USERNAME=${appDefaultUser} + - ADMIN_DEFAULT_HOSTNAME=${appDefaultHost} - ADMIN_DEFAULT_PASSWORD=${appDefaultPass} - SECRET_ACCESS=${appSecretAccess} - SECRET_REFRESH=${appSecretRefresh} diff --git a/server/admin/default-account.js b/server/admin/default-account.js index 3da6b6d..d19fcca 100644 --- a/server/admin/default-account.js +++ b/server/admin/default-account.js @@ -7,7 +7,7 @@ module.exports = async () => { await sequelize.sync(); //this whole file is just one big BUGFIX //validate env variables - if (!process.env.ADMIN_DEFAULT_USERNAME || !process.env.ADMIN_DEFAULT_PASSWORD) { + if (!process.env.ADMIN_DEFAULT_USERNAME || !process.env.ADMIN_DEFAULT_HOSTNAME || !process.env.ADMIN_DEFAULT_PASSWORD) { //skip this if arguments are missing return; } @@ -25,9 +25,8 @@ module.exports = async () => { }); if (adminRecord == null) { - const webAddress = process.env.WEB_ADDRESS == 'localhost:3000' ? 'example.com' : process.env.WEB_ADDRESS; //can't log in as "localhost" await accounts.create({ - email: `${process.env.ADMIN_DEFAULT_USERNAME}@${webAddress}`, + email: `${process.env.ADMIN_DEFAULT_USERNAME}@${process.env.ADMIN_DEFAULT_HOSTNAME}`, username: `${process.env.ADMIN_DEFAULT_USERNAME}`, hash: await bcrypt.hash(`${process.env.ADMIN_DEFAULT_PASSWORD}`, await bcrypt.genSalt(11)), type: 'normal', @@ -35,6 +34,6 @@ module.exports = async () => { mod: true }); - console.warn(`Created default admin account (email: ${process.env.ADMIN_DEFAULT_USERNAME}@${webAddress}; password: ${process.env.ADMIN_DEFAULT_PASSWORD})`); + console.warn(`Created default admin account (email: ${process.env.ADMIN_DEFAULT_USERNAME}@${process.env.ADMIN_DEFAULT_HOSTNAME}; password: ${process.env.ADMIN_DEFAULT_PASSWORD})`); } }; diff --git a/tools/debug-startup.sql b/tools/debug-startup.sql index 56f5787..b7000f6 100644 --- a/tools/debug-startup.sql +++ b/tools/debug-startup.sql @@ -1,4 +1,4 @@ #use this while debugging -CREATE DATABASE IF NOT EXISTS auth; -CREATE USER IF NOT EXISTS 'auth'@'%' IDENTIFIED BY 'charizard'; +CREATE DATABASE auth; +CREATE USER 'auth'@'%' IDENTIFIED BY 'charizard'; GRANT ALL PRIVILEGES ON auth.* TO 'auth'@'%';