Skip to content

Generate JWT Secret if not provided#70

Merged
Cod-e-Codes merged 3 commits intoCod-e-Codes:mainfrom
aleksen:main
Feb 14, 2026
Merged

Generate JWT Secret if not provided#70
Cod-e-Codes merged 3 commits intoCod-e-Codes:mainfrom
aleksen:main

Conversation

@aleksen
Copy link
Contributor

@aleksen aleksen commented Feb 12, 2026

Pull Request

Description

When I was trying to run marchat server locally to test it out, I used the interactive setup guide. It did not ask me for the JWT Secret, so it was set to a hardcoded string. Perhaps this could be a problem for other people setting up marchat servers using the interactive flag. So I could either add the JWT Secret to the interactive setup, or make the default be a generated hex value.

Also, some of the tests failed on my computer, since I already had a working setup in ~/.config/marchat. I inserted t.TempDir() in the tests that used the default location.

Fixes # (issue)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Checklist

  • My code builds and passes all tests/CI
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated documentation as needed
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have assigned reviewers

@Cod-e-Codes
Copy link
Owner

This is a solid fix.

Generating a JWT secret when one isn’t provided makes sense and updating the tests to use t.TempDir() to avoid interfering with existing configs is a good idea.

One small thing to consider before merge: if the JWT secret is generated at runtime, it would be good to ensure it’s also persisted (e.g., via saveConfigToEnv() in config_ui.go) so it survives restarts instead of changing each run.

Happy to approve once we decide whether persistence should be part of this PR or handled separately.

@aleksen
Copy link
Contributor Author

aleksen commented Feb 14, 2026

Thanks for the feedback. I can add that to this PR if you like?

@Cod-e-Codes
Copy link
Owner

Yes, please that would be great.

@aleksen
Copy link
Contributor Author

aleksen commented Feb 14, 2026

@Cod-e-Codes Let me know if this is not the desired approach to solve the config_ui.go issue. With this change we are in practice generating the JWT Secret twice.

@Cod-e-Codes
Copy link
Owner

This approach is fine. The double generation is trivially cheap and the right secret (the one saved to .env) is the one that gets used. Looks good, thanks!

@Cod-e-Codes Cod-e-Codes merged commit 9d43488 into Cod-e-Codes:main Feb 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants