Check for present User ID in Blazor PWA Application,I want to check if this User is in the List with the users data I hard coded

27 views Asked by At

This is the logic I am trying to write,I want to get the users from my hard coded list with users and get the id from the localStorage of the user that tries to currently login with it(the Id is like the password in this case,they have separate real Id,called userId),but what I want to do is take the Id that they typed from the local storage and check if this Id is already registered.I hope that was clear.

private DataModel data = new DataModel();



public class DataModel
 {

     public int Id { get; set; }

     public string UserId { get; set; }

     public string SMSCode { get; set; }

     public string Token { get; set; }

    
 }


 private List<DataModel> users = new List<DataModel>();



 private async void HandleLogin()
 {

     Console.WriteLine("Log me in!");
     var id = 0;

     var userslist = await IuserService.getUsers();
     var usersfirstid = userslist.First();
     
   

     if (usersfirstid.Id == 0)
     {
         id = id + 1;
     }
     else
     {
         id = id + 1;
     }


     var user = userslist.Where(x => x.Id != id).First();

    

     if (user==null)
     {
         errorMessage = true;
     }
     else
     {
         var randomId = Guid.NewGuid().ToString();
         id = id + 1;
         await LocalStorage.SetItemAsync<int>("id", id);
         await LocalStorage.SetItemAsync<string>("userId", randomId);
     }

     await AuthStateProvider.GetAuthenticationStateAsync();


     NavManager.NavigateTo("/verificar");


 }
0

There are 0 answers