Skip to content

Commit

Permalink
chore: 🤖 NEXTAUTH_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ZingerLittleBee committed Apr 28, 2024
1 parent 429ad26 commit 990c0cb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/hub/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DATABASE_URL="file:./serverhub.db"
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_SECRET=""
# NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_URL="http://localhost:3000"

MONGODB_URI=mongodb://mongoadmin:secret@localhost:27017/

Expand Down
16 changes: 8 additions & 8 deletions apps/hub/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const env = createEnv({
process.env.NODE_ENV === 'production'
? z.string()
: z.string().optional(),
// NEXTAUTH_URL: z.preprocess(
// // This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// // Since NextAuth.js automatically uses the VERCEL_URL if present.
// (str) => process.env.VERCEL_URL ?? str,
// // VERCEL_URL doesn't include `https` so it cant be validated as a URL
// process.env.VERCEL ? z.string() : z.string().url()
// ),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth.js automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string() : z.string().url()
),
SALT_ROUNDS: z
.union([
z.string().refine((value) => !isNaN(Number(value)), {
Expand Down Expand Up @@ -51,7 +51,7 @@ export const env = createEnv({
runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
// NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
SALT_ROUNDS: process.env.SALT_ROUNDS,
SERVER_JWT_SECRET: process.env.SERVER_JWT_SECRET,
MONGODB_URI: process.env.MONGODB_URI,
Expand Down
2 changes: 1 addition & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DATABASE_URL="file:/app/serverhub.db"
# openssl rand -base64 32
NEXTAUTH_SECRET="Your_NextAuth_Secret_Key"
# ServerHub URL
# NEXTAUTH_URL="http://localhost"
NEXTAUTH_URL="https://serverhub.app"

# MongoDB
MONGO_INITDB_ROOT_USERNAME=mongoadmin
Expand Down
27 changes: 13 additions & 14 deletions script/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ ERROR='\033[1;31m'
NC='\033[0m' # No Color

# Declare variables

use_external_mongo=""
# SERVERHUB_URL=""
SERVERHUB_URL=""
RECORDER_DOMAIN=""
MONGO_INITDB_ROOT_USERNAME=""
MONGO_INITDB_ROOT_PASSWORD=""
Expand Down Expand Up @@ -50,18 +49,18 @@ check_tools_installed() {

# Function to write values to .env file
write_to_env_file() {
# local serverhub_url=$1
local nextauth_secret=$1
local mongo_initdb_root_username=$2
local mongo_initdb_root_password=$3
local mongodb_uri=$4
local server_jwt_secret=$5
local serverhub_url=$1
local nextauth_secret=$2
local mongo_initdb_root_username=$3
local mongo_initdb_root_password=$4
local mongodb_uri=$5
local server_jwt_secret=$6

cat <<EOF >.env
RUST_LOG=waring
DATABASE_URL="file:/app/serverhub.db"
NEXTAUTH_SECRET="${nextauth_secret}"
#NEXTAUTH_URL="${serverhub_url}"
NEXTAUTH_URL="${serverhub_url}"
MONGO_INITDB_ROOT_USERNAME="${mongo_initdb_root_username}"
MONGO_INITDB_ROOT_PASSWORD="${mongo_initdb_root_password}"
MONGODB_URI="${mongodb_uri}"
Expand Down Expand Up @@ -132,9 +131,9 @@ installation() {
# Prompt user to start installation
echo -e "\n${INFO}Starting application installation...${NC}\n"

# echo -e "${WARNING}Enter the ServerHub URL (Example: https://serverhub.app):${NC}"
# echo -e "${INFO}(Make sure to ${WARNING}include the protocol${INFO}.)${NC}"
# read -r SERVERHUB_URL
echo -e "${WARNING}Enter the ServerHub URL (Example: https://serverhub.app):${NC}"
echo -e "${INFO}(Make sure to ${WARNING}include the protocol${INFO}.)${NC}"
read -r SERVERHUB_URL

echo -e "\n${WARNING}Enter the Recorder service domain (Example: recorder.serverhub.app):${NC}"
echo -e "${INFO}(Make sure to ${WARNING}exclude the protocol${INFO}.)${NC}"
Expand All @@ -155,7 +154,7 @@ installation() {
print_and_confirm_variables() {
echo -e "\n${INFO}Please reconfirm input variable:${NC}"
echo -e "========================================================"
# echo -e "${INFO}SERVERHUB_URL:${NC} ${WARNING}$SERVERHUB_URL${NC}"
echo -e "${INFO}SERVERHUB_URL:${NC} ${WARNING}$SERVERHUB_URL${NC}"
echo -e "${INFO}RECORDER_DOMAIN:${NC} ${WARNING}$RECORDER_DOMAIN${NC}"

if [[ -n $MONGO_INITDB_ROOT_USERNAME ]]; then
Expand Down Expand Up @@ -192,7 +191,7 @@ installation() {
write_to_caddy_file "$RECORDER_DOMAIN"

# Write the generated values to .env file using the function
write_to_env_file "$NEXTAUTH_SECRET" "$MONGO_INITDB_ROOT_USERNAME" "$MONGO_INITDB_ROOT_PASSWORD" "$MONGODB_URI" "$SERVER_JWT_SECRET"
write_to_env_file "$NEXTAUTH_URL" "$NEXTAUTH_SECRET" "$MONGO_INITDB_ROOT_USERNAME" "$MONGO_INITDB_ROOT_PASSWORD" "$MONGODB_URI" "$SERVER_JWT_SECRET"

if [[ $use_external_mongo == "y" ]]; then
sed -i '/[ \t]*mongo/,/[ \t]*hub/{/[ \t]*hub/!d}' docker-compose.yml
Expand Down

0 comments on commit 990c0cb

Please sign in to comment.