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 Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,679 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 15,261 Reputation points Microsoft Employee
    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>