Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ func main() {

services.InitDebateVsBotService(cfg)
services.InitCoachService()
// Connect to MongoDB using the URI from the configuration

if err := db.ConnectMongoDB(cfg.Database.URI); err != nil {
log.Fatalf("Failed to connect to MongoDB: %v", err)
}
log.Println("Connected to MongoDB")

utils.SetJWTSecret(cfg.JWT.Secret)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the configuration structure supports JWT.Secret field.

The JWT secret initialization looks correct and is well-placed after DB connection. Please ensure the config structure includes the JWT.Secret field.


🏁 Script executed:

#!/bin/bash
# Description: Verify that the config structure includes JWT.Secret field and the config file exists

# Check if config structure defines JWT.Secret
ast-grep --pattern $'type Config struct {
  $$$
  JWT $_ {
    $$$
    Secret $_
    $$$
  }
  $$$
}'

# Check if the config file exists and contains JWT secret
if [ -f "backend/config/config.prod.yml" ]; then
  echo "Checking config.prod.yml for JWT configuration:"
  cat backend/config/config.prod.yml | grep -A 5 -B 2 -i jwt || echo "No JWT section found in config file"
else
  echo "Config file backend/config/config.prod.yml not found"
fi

Length of output: 598


To confirm the Config struct’s definition and ensure it includes the JWT.Secret field, let’s locate its declaration in the codebase:


🏁 Script executed:

#!/bin/bash
# Locate and inspect the Config struct to verify JWT.Secret is defined
rg -n 'type Config struct' -A20 --color=never

Length of output: 1102


Add missing JWT field to the Config struct

The Config struct in backend/config/config.go does not define a JWT section, so cfg.JWT.Secret will not be populated. Please update the struct to include it:

• File: backend/config/config.go, inside type Config struct { … }

 type Config struct {
   Server struct {
     Port int `yaml:"port"`
   } `yaml:"server"`
   Cognito struct { … } `yaml:"cognito"`
   Openai struct { … } `yaml:"openai"`
   Gemini struct { … } `yaml:"gemini"`
   Database struct { … } `yaml:"database"`
+    JWT struct {
+      Secret string `yaml:"secret"`
+      Expiry int    `yaml:"expiry"` // if you also want to capture token expiry
+    } `yaml:"jwt"`
 }

• Ensure your YAML config (e.g. backend/config/config.prod.yml) remains:

jwt:
  secret: '<YOUR_JWT_SECRET>'
  expiry: 1440

After this change, utils.SetJWTSecret(cfg.JWT.Secret) will correctly receive the configured value.

🤖 Prompt for AI Agents
In backend/config/config.go around the definition of the Config struct, add a
JWT field that includes a Secret string field to match the expected structure
used in main.go. This will ensure cfg.JWT.Secret is properly populated from the
configuration file. Confirm the YAML config file backend/config/config.prod.yml
contains the jwt section with secret and expiry keys as expected. This update
will allow utils.SetJWTSecret(cfg.JWT.Secret) to receive the correct JWT secret
value.


// Seed initial debate-related data
utils.SeedDebateData()
utils.PopulateTestUsers()
Expand Down
9 changes: 5 additions & 4 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type Config struct {
} `yaml:"database"`

JWT struct {
Secret string // Add JWT secret
Expiry int // Token expiry in minutes
Secret string `yaml:"secret"`
Expiry int `yaml:"expiry"`
}
Comment on lines 34 to 37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing YAML struct tag for JWT configuration.

The JWT struct is missing the yaml:"jwt" tag, which will prevent proper parsing from YAML files.

 	JWT struct {
 		Secret string `yaml:"secret"`
 		Expiry int    `yaml:"expiry"`
-	}
+	} `yaml:"jwt"`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JWT struct {
Secret string // Add JWT secret
Expiry int // Token expiry in minutes
Secret string `yaml:"secret"`
Expiry int `yaml:"expiry"`
}
JWT struct {
Secret string `yaml:"secret"`
Expiry int `yaml:"expiry"`
- }
+ } `yaml:"jwt"`
🤖 Prompt for AI Agents
In backend/config/config.go around lines 34 to 37, the JWT struct lacks the
yaml:"jwt" tag needed for proper YAML parsing. Add the yaml:"jwt" struct tag to
the JWT struct definition so that the entire JWT configuration block is
correctly mapped when unmarshalling from YAML files.


SMTP struct { // Add SMTP configuration
Host string
Port int
Expand All @@ -43,8 +44,8 @@ type Config struct {
SenderEmail string // Same as Username for Gmail
SenderName string
}
GoogleOAuth struct { // Add Google OAuth configuration
ClientID string
GoogleOAuth struct {
ClientID string `yaml:"clientID"`
}
}
Comment on lines +47 to 50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing YAML struct tag for GoogleOAuth configuration.

The GoogleOAuth struct is missing the yaml:"googleOAuth" tag, which will prevent proper parsing from YAML files.

 	GoogleOAuth struct {
 		ClientID string `yaml:"clientID"`
-	}
+	} `yaml:"googleOAuth"`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
GoogleOAuth struct {
ClientID string `yaml:"clientID"`
}
}
GoogleOAuth struct {
ClientID string `yaml:"clientID"`
} `yaml:"googleOAuth"`
}
🤖 Prompt for AI Agents
In backend/config/config.go around lines 47 to 50, the GoogleOAuth struct lacks
the yaml struct tag for the entire struct, which is necessary for correct YAML
unmarshalling. Add the tag `yaml:"googleOAuth"` to the GoogleOAuth struct
definition to ensure it maps properly when parsing the YAML configuration file.


Expand Down
43 changes: 43 additions & 0 deletions backend/config/config.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
server:
port: 1313 # The port number your backend server will run on

database:
uri: 'mongodb+srv://<username>:<password>@<cluster-url>/<database-name>'
# Replace with your MongoDB Atlas connection string
# Get this from your MongoDB Atlas dashboard after creating a cluster and database

gemini:
apiKey: '<YOUR_GEMINI_API_KEY>'
# API key for OpenAI / Gemini model access
# Obtain from your OpenRouter.ai or OpenAI account dashboard

jwt:
secret: '<YOUR_JWT_SECRET>'
# A secret string used to sign JWT tokens
# Generate a strong random string (e.g. use `openssl rand -hex 32`)

expiry: 1440
# Token expiry time in minutes (e.g. 1440 = 24 hours)

smtp:
host: 'smtp.gmail.com'
# SMTP server host for sending emails (example is Gmail SMTP)

port: 587
# SMTP server port (587 for TLS)

username: '<YOUR_EMAIL_ADDRESS>'
# Email username (your email address)

password: '<YOUR_EMAIL_PASSWORD_OR_APP_PASSWORD>'
# Password for the email or app-specific password if 2FA is enabled

senderEmail: '<YOUR_EMAIL_ADDRESS>'
# The 'from' email address used when sending mails

senderName: 'DebateAI Team'

googleOAuth:
clientID: '<YOUR_GOOGLE_OAUTH_CLIENT_ID>'
# Google OAuth Client ID for OAuth login
# Obtain from Google Cloud Console (APIs & Services > Credentials > OAuth 2.0 Client IDs)
Loading