nul800sebastiaan / YubiKey2Factor

2FA with Google Authenticator and YubiKey
MIT License
3 stars 10 forks source link

Update some changes in TwoFactorEnabled function. #2

Open rbalai429 opened 3 years ago

rbalai429 commented 3 years ago

When I'm trying this package everything works fine but after enabling 2FA when I click on another tab (eg. Media, Documents) in Umbraco back office then on the bottom showing two buttons, First one Discard and another Stay. When I press discard and then I checked in DB, successfully entry of user for 2FA in TwoFactor table. But in Umbraco back-office console showing an error or I'm getting a 500 error for TwoFactorEnabled API (Object reference not null).

public List<TwoFactorAuthInfo> TwoFactorEnabled(int userId = 0) { var database = DatabaseContext.Database; var user = Security.CurrentUser; userId = user != null ? user.Id : userId; var result = database.Fetch<TwoFactor>("WHERE [userId] = @userId AND [confirmed] = 1", new { userId }); var twoFactorAuthInfo = new List<TwoFactorAuthInfo>(); if (result.Any()) { foreach (var factor in result) { var authInfo = new TwoFactorAuthInfo { ApplicationName = factor.Key }; twoFactorAuthInfo.Add(authInfo); } } return twoFactorAuthInfo; }

I update this code and they work fine for me.