Skip to content

Commit

Permalink
Fully tested the remote database
Browse files Browse the repository at this point in the history
Added configurable hostname for default account email
  • Loading branch information
Ratstail91 committed May 2, 2024
1 parent 6859b36 commit 0bc7cb1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .envdev
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM node:21-bookworm-slim
FROM node:22-bookworm-slim
WORKDIR "/app"
COPY package*.json /app
RUN npm install --production
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configure-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 3 additions & 4 deletions server/admin/default-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -25,16 +25,15 @@ 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',
admin: true,
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})`);
}
};
4 changes: 2 additions & 2 deletions tools/debug-startup.sql
Original file line number Diff line number Diff line change
@@ -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'@'%';

0 comments on commit 0bc7cb1

Please sign in to comment.