Skip to content

Commit

Permalink
fix(back): do not fail when SMS disabled (no ApiKey) : just a warning…
Browse files Browse the repository at this point in the history
… log
  • Loading branch information
agjini committed Oct 16, 2024
1 parent ea0341c commit 45bce0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static IMongoDatabase GetDatabase(MongoSettings settings, AuthSettings?

if (authSettings?.TestAccount is not null)
{
var phone = authSettings.TestAccount.ToPhoneNumber().ToString();
var phone = authSettings.TestAccount.ToPhoneNumber();
var testUser = db.GetCollection<DbUser>()
.Find(u => u.Phone == phone)
.FirstOrDefault();
Expand Down
8 changes: 7 additions & 1 deletion back/src/Liane/Liane.Service/Internal/User/SmsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ public sealed class SmsSender(ILogger<SmsSender> logger, SmsSettings smsSettings

public async Task Send(string phone, string message)
{
if (smsSettings.ApiKey is null)
{
logger.LogWarning("API key is missing, sms not sent to {0} with message {1}", phone, message);
return;
}

var sendTransacSms = new SendTransacSms(
"Liane",
phone,
message,
SendTransacSms.TypeEnum.Transactional,
"auth",
"https://dev.liane.app"
);
);

try
{
Expand Down
17 changes: 3 additions & 14 deletions back/src/Liane/Liane.Service/Internal/User/UserServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@

namespace Liane.Service.Internal.User;

public sealed class UserServiceImpl : BaseMongoCrudService<DbUser, Api.Auth.User>, IUserService
public sealed class UserServiceImpl(IMongoDatabase mongo) : BaseMongoCrudService<DbUser, Api.Auth.User>(mongo), IUserService
{
public UserServiceImpl(IMongoDatabase mongo) : base(mongo)
{
}

public override async Task<Api.Auth.User> Get(Ref<Api.Auth.User> reference)
{
try
Expand Down Expand Up @@ -62,18 +58,11 @@ public async Task<bool> IsSignedUp(string phone)
{
var phoneNumber = phone.ToPhoneNumber();

var number = phoneNumber.ToString();

var dbUser = await Mongo.GetCollection<DbUser>()
.Find(u => u.Phone == number)
.Find(u => u.Phone == phoneNumber)
.FirstOrDefaultAsync();

if (dbUser is null)
{
return false;
}

return dbUser.UserInfo is not null;
return dbUser?.UserInfo is not null;
}

public async Task<FullUser> GetFullUser(string userId)
Expand Down

0 comments on commit 45bce0d

Please sign in to comment.