Angular local storage issues with Https in linux server

I have a Linux server where I host a Laravel API and an Angular front-end application. This server has a virtual host for the Laravel API and also hosts the Angular front-end application. The Angular application uses local storage to save the user levels of logged-in users, such as administrator, user, etc. I tried accessing the front end using HTTP, and it works without any errors. Now, I have added an SSL certificate to this server and am trying to access the Angular application via HTTPS. However, local storage does not work properly in this case. I checked the web browser console, and the storage values are present and correctly spelled. This issue only occurs with HTTPS.

What could be the possible cause for this?. See the following code segment for get idea.

angular function

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>onSubmit(){
this.authService.signin(this.loginForm.value).subscribe(
result => {
this.responseHandler(result);
},
error => {
this.errors = error.error;
if(this.errors?.name)
{
this.toastr.error(this.errors.name,'Login');
}
else if(this.errors?.password)
{
this.toastr.error(this.errors.password,'Login');
}
else if(this.errors?.message)
{
this.toastr.error(this.errors.message,'Login');
}
else
{
this.toastr.error(error.name,'Login');
}
},() => {
this.setCookie2();
this.toastr.success("Success",'Login');
this.authState.setAuthState(true);
localStorage.setItem('Islogin', 'true');
localStorage.setItem('login', this.loginForm.value.name);
location.reload();
}
);
}
</code>
<code>onSubmit(){ this.authService.signin(this.loginForm.value).subscribe( result => { this.responseHandler(result); }, error => { this.errors = error.error; if(this.errors?.name) { this.toastr.error(this.errors.name,'Login'); } else if(this.errors?.password) { this.toastr.error(this.errors.password,'Login'); } else if(this.errors?.message) { this.toastr.error(this.errors.message,'Login'); } else { this.toastr.error(error.name,'Login'); } },() => { this.setCookie2(); this.toastr.success("Success",'Login'); this.authState.setAuthState(true); localStorage.setItem('Islogin', 'true'); localStorage.setItem('login', this.loginForm.value.name); location.reload(); } ); } </code>
onSubmit(){


    this.authService.signin(this.loginForm.value).subscribe(
      result => {
        this.responseHandler(result);
      },
      error => {
        this.errors = error.error;
        if(this.errors?.name)
        {
          this.toastr.error(this.errors.name,'Login');
        }
        else if(this.errors?.password)
        {
          this.toastr.error(this.errors.password,'Login');
        }
        else if(this.errors?.message)
        {
          this.toastr.error(this.errors.message,'Login');
        }

        else
        {
          this.toastr.error(error.name,'Login');
        }
      },() => {
       this.setCookie2();
        this.toastr.success("Success",'Login');
        this.authState.setAuthState(true);
        localStorage.setItem('Islogin', 'true');
        localStorage.setItem('login', this.loginForm.value.name);
        location.reload();
      }
    );
  }

handle the response

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>responseHandler(data){
this.token.handleData(data.access_token);
this.key=data.key;
localStorage.setItem('role',data.user_role.user_group);
}
</code>
<code>responseHandler(data){ this.token.handleData(data.access_token); this.key=data.key; localStorage.setItem('role',data.user_role.user_group); } </code>
responseHandler(data){
    this.token.handleData(data.access_token);
    this.key=data.key;
    localStorage.setItem('role',data.user_role.user_group);
  }

Following is Laravel API response

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovLzEwLjEyOC40MS4yMjI6NDIwMC9hcGkvYXV0aC9sb2dpbiIsImlhdCI6MTcyMDU4NTkxMCwiZXhwIjoxNzUyMTIxOTEwLCJuYmYiOjE3MjA1ODU5MTAsImp0aSI6IjZ4OU9RYTVlZW5aaWZvcE8iLCJzdWIiOiIyODgiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.5EmgI3nX0QM-26hHKcrcem_l7wdkRXymuWvUxwowVQg",
"key": "dab84054ff07240ae4bc255aa26cc187",
"token_type": "bearer",
"expires_in": 31536000,
"user": {
"id": 288,
"name": "admin",
"email": "[email protected]",
"email_verified_at": null,
"created_at": "2024-02-16T16:32:00.000000Z",
"updated_at": "2024-02-16T16:32:00.000000Z",
"user_fullname": "admin",
"user_type": "local",
"web_access": "Enabled",
"pager": "94789654123",
"apache_password": "f865b53623b121fd34ee5426c792e5c33af8c227",
"reset": "false"
},
"user_role": {
"user_group": "Administrator"
}
}
</code>
<code>{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovLzEwLjEyOC40MS4yMjI6NDIwMC9hcGkvYXV0aC9sb2dpbiIsImlhdCI6MTcyMDU4NTkxMCwiZXhwIjoxNzUyMTIxOTEwLCJuYmYiOjE3MjA1ODU5MTAsImp0aSI6IjZ4OU9RYTVlZW5aaWZvcE8iLCJzdWIiOiIyODgiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.5EmgI3nX0QM-26hHKcrcem_l7wdkRXymuWvUxwowVQg", "key": "dab84054ff07240ae4bc255aa26cc187", "token_type": "bearer", "expires_in": 31536000, "user": { "id": 288, "name": "admin", "email": "[email protected]", "email_verified_at": null, "created_at": "2024-02-16T16:32:00.000000Z", "updated_at": "2024-02-16T16:32:00.000000Z", "user_fullname": "admin", "user_type": "local", "web_access": "Enabled", "pager": "94789654123", "apache_password": "f865b53623b121fd34ee5426c792e5c33af8c227", "reset": "false" }, "user_role": { "user_group": "Administrator" } } </code>
{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovLzEwLjEyOC40MS4yMjI6NDIwMC9hcGkvYXV0aC9sb2dpbiIsImlhdCI6MTcyMDU4NTkxMCwiZXhwIjoxNzUyMTIxOTEwLCJuYmYiOjE3MjA1ODU5MTAsImp0aSI6IjZ4OU9RYTVlZW5aaWZvcE8iLCJzdWIiOiIyODgiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.5EmgI3nX0QM-26hHKcrcem_l7wdkRXymuWvUxwowVQg",
    "key": "dab84054ff07240ae4bc255aa26cc187",
    "token_type": "bearer",
    "expires_in": 31536000,
    "user": {
        "id": 288,
        "name": "admin",
        "email": "[email protected]",
        "email_verified_at": null,
        "created_at": "2024-02-16T16:32:00.000000Z",
        "updated_at": "2024-02-16T16:32:00.000000Z",
        "user_fullname": "admin",
        "user_type": "local",
        "web_access": "Enabled",
        "pager": "94789654123",
        "apache_password": "f865b53623b121fd34ee5426c792e5c33af8c227",
        "reset": "false"
    },
    "user_role": {
        "user_group": "Administrator"
    }
}

Please provide me with possible reasons for my case.

New contributor

HiroMB is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật