How to refresh the page after login in angular application?

ms member 6 Reputation points
2020-08-27T07:21:12.927+00:00

I am using @azure/msal-angular npm package here i am logging in angular app and after login it will redirect to home page as there are some post request in my home page this are not getting loaded and after refreshing the page then the apis are getting called.

How to solve it.

Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2020-08-27T15:13:22.237+00:00

    You'll need to develop something similar:

    @Injectable()
    class UserService() {
    
        private _isLoggedIn = new BehaviorSubject<boolean>(false);
    
        login_user(form: string) {
            // Call this._isLoggedIn.next(true) or this._isLoggedIn.next(false) depending on the result
        }
    
        get isLoggedIn() {
            return this._isLoggedIn.asObservable();
        }
    }
    

    Then in the component where you want to display the login/logout button, add private userService: UserService in the constructor, then write something like this in the template:
    <button>{{ userService.isLoggedIn | async ? 'Logout' : 'Login' }}</button>


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.