Blazor Server - Force user to sign out and re-direct to Login Page - authorization

I am using roles based authorization in my Blazor server app. When a user is viewing any component, something in the database could change behind the scenes.
I would want to force the user to be logged out and back in again if they navigated to any other components. (ie the state of their authentication has changed).
I've tried using the SignInManager.SignOutAsync() and NavigationManager.Navigate in app.razor to Sign out the user and Navigate to the Login page, but I find that the component they are trying to hit will still draw for a split second before it Navigates away. Is there a way to have the Navigation manager in the app.razor to immediately navigate away without letting the Page from drawing first.

do a client-side POST to a controller method containing SignInManager.SignOutAsync(), followed by NavigationManager.NavigateTo with forceLoad set to true to the Login page

Related

Cookies in Vue SSR

I am building an app using .Net Core with VueJs along with JavascriptServices&NodeServices for ServerSideRendering, and Identity as auth mechanism.
Scenario :
I navigate to /details page - having some hidden info because the user is not logged in (so, User.Identity.Name) is null.
I click login, a pop-up shows up, I enter my credentials, and after the AJAX call is made to auth the user, I do a full refresh of the page using location.reload(true).
This works on chrome desktop but on mobile devices it doesn't; on mobile browsers it works if I "fake navigate away" meaning that I go back one page and then come back (so I don't trigger a SSR).
Does anybody have an idea why this doesn't work?

Admin app with React - how not to expose APIs until login succeeds?

Here is the workflow I want to implement for admin module of a site
Show a login screen - will be a React component
If login fails, the above component will show an error message
If login succeeds, the view changes. The new view should contain links to APIs /addProduct and /deleteProduct
One way is to create one single App but I don't want to expose API urls to the client unless the login succeeds.
How do I achieve UI seperation here?
I would say that you have two options:
Use the login response to return the list of links.
Have a set endpoint that only works with an authenticated client that returns the list of links.

common login screen from each controller action on session timeout

We are implementing multi page MVC 4 web site. Here we require user to be authenticated all the time.
I am able to place login screen on Layout page and launch it on ajax click action in header.
But our requirement is that, on every controller action, if session is invalid, we need to show login screen as popup else action should do its designated task.
Please suggest how can i launch it from the controller. Currently we are using separate page for Login where we redirect when we found invalid session on any controller action.
Thanks and Regards,
Vikas Nale

expressJS rendering login bootstrap modal if action is not authenticated

I am writing an expressjs/ejs app which is using Twitter Bootstrap 3 for web pages. I have used Bootstrap Modal for login. I have included the modal in the header section so it is available for every webpage. However, if a user has not logged in, he needs to be authenticated before performing certain actions on the app. I am using a middleware function to determine whether a user is logged in, however if a user is not logged in, I need to redirect him to home page and initiate the login model directly. I am not sure how I can initiate the bootstrap modal from server side. Any thoughts?
I need to be able to do:
response.render('/home#loginModal');
That way user is directed to home page and is given a chance to login.

How can I get devise to go to use one page as root if the user is logging in but another when they are logging out?

I'm working on a Rails 3 application that uses devise for user authentication. I would like the user to only see the splash/signup page when they first visit the site but be sent to the login page if they log out or time out, as follows:
Splash page
Click on login link
Login page
Supply proper login credentials
User's dashboard
Click on logout link or user times out
Login page (not splash page)
Take a look in the devise wiki: How To: Change the redirect path after destroying a session i.e. signing out