Authentication after page loads

I have the following on a page:
@page "/"

@(Security.User?.UserName)

@code {
[Inject]
protected SecurityService Security { get; set; }

}

The first time it shows 'Anonymous' then I go to a different page and return and it shows 'dave' (my username). Why didn't it initially show 'dave'?

Thanks,
Dave

Hi @davevorgang,

I'm unable to reproduce such problem. You can check this application for reference.

Hi enchev,

When I run your sample it works as expected. Mine still does not fire off the Authenticated method until after it goes to the OnInitializedAsync and then the Authenticated gets fired.

So the sequence is:
MainLayoutComponent.OnInitializedAsync
MainPageComponent.OnInitializedAsync
MainLayoutComponent.Authenticated

I can send you my actual test app if that helps.

Thanks,
Dave

Hi Dave,

If we can have your application where we can reproduce the problem we will be able to provide more info.

I emailed you my solution file a few days ago. I could not upload it directly to the forum. The email address I used was info@radzen.com.

Thanks,
Dave

Hi @davevorgang,

We’ve not received anything from you. If the attachment is too big you can share it somewhere and send us the link.

Thank you, here is the link: https://drive.google.com/file/d/1VyHiuQEt7lrD1z93Nvc8kUq8MBpzprUi/view?usp=sharing

I've tried your app however I'm unable to reproduce the problem again:


It shows the name without navigating to other pages.

But when I login using a username from the security database the user name is Anonymize. Not the username that I logged in with.

Were you able to test this out? It show's Anonymous instead of the username. If I use the Admin username it works fine but if I use a real username from the security database then it shows Anonymous.

In my production program it shows Anonymous and the my real username about 1 second later. I can send you a video of that if you wish.

I've tested both admin/admin and normal user login - the result was the same:

I'm not sure that I can add anything else to this thread.

Thanks for trying but I'm wondering if you can try one more thing out. This sample just has the username displayed on the MainLayout. When using Admin it displays correctly. When using A real username from the data base it displays Anonymous.

The code is here: https://drive.google.com/file/d/1_wTLQW9YEJ-6OvruktTZLcKB210sjkBw/view?usp=sharing

Can you please try it out?

Thank you.

Here is what I have with this app:


This bug has happened to me, and it seems that to other users too. This is the current workaround.

1 Like

Hey @kim,

Not sure if this is related however we will add in the next update FindByNameAsync() in the security service if FindByEmailAsync() fails to find the user.

2 Likes

enchev, that would be good even if it does not fix my problem that I sent you. I currently do the work around that kim suggested in my production version because I use the email as the login.

But, that fix is not relevant to the current problem. And, I don't know why when you run the program using a username from the database that it works for you but I get Anonymous.

Update: I may be wrong and the work-around may work. I'll try that out again on the version I sent you.

FindByNameAsync does take care of retrieving the correct user. I should have known this because this is what I have in my production version. However, the real problem is the sequence of methods that called when admin is used as opposed to a real username. Here is where I have breakpoints:

When admin is used the sequence is:
1.MainLayoutComponent: OnInitializedAsync
2.MainLayoutComponent: Authenticated
3.GendersComponent: OnInitializedAsync
4.MainLayoutComponent: Authenticated

When a real username from the database is used the sequence is:
1.MainLayoutComponent: OnInitializedAsync
2.GendersComponent: OnInitializedAsync
3.MainLayoutComponent: Authenticated
4.MainLayoutComponent: Authenticated

I need to have the real usernames use the same calling sequence as the admin username.

Thanks,
Dave

This isn't possible as real user name makes a DB request.

Having said that we are still unable to reproduce the problem. Without a reproduction we cannot suggest a fix.

My previous problem with the Anonymous user may be related to this problem. When I made my application, I made an user named 'Admin' with a password that isn't 'admin' (didn't know that admin/admin existed back then). I guess the generated code is stressing when you make an user with the same name as the admin user. Don't know for sure though. Hopefully this helps a bit!

I had the same results using your sample project. I have created a video showing the problem. Here is the link: https://drive.google.com/file/d/1FaqhIHptYFSv6bUQ-2LykpTNXFus_QYN/view?usp=sharing

If you could take a look at that and then reproduce I would really appreciate it.

Thanks,
Dave