diff --git a/auth/config/app/config.go b/auth/config/app/config.go index ede9ab9b8..707ea19cc 100644 --- a/auth/config/app/config.go +++ b/auth/config/app/config.go @@ -131,21 +131,23 @@ func (c *Config) GetDefaultUserData() (*accountEntities.Account, error) { if c.DefaultUserData == enums.DefaultUserData { logger.LogWarn(enums.MessageWarningDefaultUser) } + if err := json.Unmarshal([]byte(c.DefaultUserData), &account); err != nil { return nil, err } + return account, nil } func (c *Config) GetApplicationAdminData() (*accountEntities.Account, error) { account := &accountEntities.Account{} - logger.LogWarn(fmt.Sprintf(enums.MessageFailedToFormatAppAdminValue, enums.EnvApplicationAdminData)) - if c.ApplicationAdminData == enums.ApplicationAdminDefaultData { logger.LogWarn(enums.MessageWarningDefaultApplicationAdmin) } + if err := json.Unmarshal([]byte(c.ApplicationAdminData), account); err != nil { + logger.LogWarn(fmt.Sprintf(enums.MessageFailedToFormatAppAdminValue, enums.EnvApplicationAdminData)) return nil, err } @@ -212,10 +214,12 @@ func (c *Config) createApplicationAdminUser() { } func (c *Config) createAccount(account *accountEntities.Account) { - err := c.databaseWrite.Create(account, accountEnums.DatabaseTableAccount).GetError() - if err != nil { - c.checkCreateAccountErrors(err, account) - return + _, err := c.getAccountByEmail(account.Email) + if err != nil && err == databaseEnums.ErrorNotFoundRecords { + if err := c.databaseWrite.Create(account, accountEnums.DatabaseTableAccount).GetError(); err != nil { + c.checkCreateAccountErrors(err, account) + return + } } logger.LogInfo(fmt.Sprintf(enums.MessageUserCreateWithSuccess, account.Username, account.Email)) diff --git a/auth/config/app/config_test.go b/auth/config/app/config_test.go index 88c4d37dc..06fcd0f43 100644 --- a/auth/config/app/config_test.go +++ b/auth/config/app/config_test.go @@ -32,6 +32,7 @@ import ( func getMockedConnection() *database.Connection { databaseMock := &database.Mock{} databaseMock.On("Create").Return(&response.Response{}) + databaseMock.On("Find").Return(&response.Response{}) return &database.Connection{Read: databaseMock, Write: databaseMock} } @@ -142,6 +143,8 @@ func TestNewAuthAppConfig(t *testing.T) { databaseMock := &database.Mock{} databaseMock.On("Create").Once().Return( response.NewResponse(0, errors.New(enums.DuplicatedAccount), nil)) + databaseMock.On("Find").Once(). + Return(response.NewResponse(0, databaseEnums.ErrorNotFoundRecords, nil)) databaseMock.On("Find").Return(&response.Response{}) databaseMock.On("Delete").Return(&response.Response{}) databaseMock.On("Create").Return(&response.Response{})