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
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
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
{
"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.
HiroMB is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.