Create initial admin-user on startup

This commit is contained in:
Torjus Håkestad 2023-10-22 22:02:36 +02:00
parent a3b5247da2
commit 83ca5ee435

View File

@ -44,6 +44,17 @@ func NewServer(config *Config) (*UserServer, error) {
srv.Handler = r
srv.store = store.NewMemoryStore()
// Add initial admin-user
u := users.User{
ID: uuid.Must(uuid.NewRandom()).String(),
Username: "admin",
}
password := uuid.Must(uuid.NewRandom()).String()
_ = u.SetPassword(password)
_ = srv.store.AddUser(u)
srv.Logger.Warn("Initial admin-user created.", "username", u.Username, "password", password)
conn, err := nats.Connect(config.NATSAddr)
if err != nil {
return nil, err