AlexKhymenko / ngx-permissions

Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
MIT License
936 stars 126 forks source link

NgxPermissionsService loosing data on page refresh #173

Closed xts-velkumars closed 3 years ago

xts-velkumars commented 3 years ago

Hi, I'm setting the permissions from Login Component like below.

Login Component

loadPermissions(roleName: string) {
        let permissions = [];
        permissions.push(roleName);
        this.permissionsService.loadPermissions(permissions);
    }

On the successful login, page will be redirected to Dashboard page. I'm doing console to check the permission ngOnInit. I'm getting the data as excepted.

If I refresh the page, I have lost my data. How I can resolve this?

Dashboard Component

  ngOnInit() {
        var permissions = this.permissionsService.getPermissions();
        console.log(permissions);
    }

Before refresh

image

After refresh

image

bikerp commented 3 years ago

I'm facing the same issue. Do you have any suggestion how to fix it?

AlexKhymenko commented 3 years ago

Hi its because angular looses all data on refresh. One suggestion for fix is described in wiki https://github.com/AlexKhymenko/ngx-permissions/wiki/common-use-cases#save-permissions-on-page-refresh