Unable to access authorization.user._id after refreshing once - angularjs

I have developed a NodeJS app (MeanJS) with Yo generator.
I think there is an issue with the authentication module.
I am trying to access the authentication.user._id value in the HTML page using {{authentication.user._id}} and it works fine for the first time when the user logs in. But as soon as the user refreshes the page, this particular value is gone. All other values in authentication.user are still there, but the "_id" value is gone until I re-login. Why is this happening?
I want the "_id" value to persist even after refreshing the page, since the user is still logged in and it is the same session.
Thanks.

In your core.server.controller.js file you need to add this line of code:
_id:validator.escape(req.user._id)
At the begining of the safeUserObject in renderIndex function. Save it, restart the server and try again.

Related

Local chat in tabs without backend

I'm trying to create a chat in React that will be attached to a browser tab. The message history must be global. I put each message to local storage with a unique name. However, in the second tab, messages appear only after the page is refreshed. If you do not refresh the page, but write something new from the second tab, the values ​​​​in localstorage begin to be overwritten.
I tried to use broadcastmessage, but I ran into the fact that it is called many times, and many identical values ​​come to localstorage at once. I didn't find a solution to this problem.
I also tried using add.edeventListener('storage') but it doesn't work for the current tab.
I also used windows.postmessage, but that didn't work either. Can you suggest how to display messages without reloading the page?

Page falls when it reloads and gives an ngix error

I have a problem with my ReactJs. I created an app that when a user inputs a username and password, it takes him to his account that has a sidebar menu with different pages and routes. The routes work properly on the local server and when I reload each page, it reloads successfully. Yet, when I deployed my website on a testing server, it falls whenever I refresh the page and returns this error :
What could be the reason for this problem considering that it works locally with ease and the route is reloaded successfully. Does anyone know how to fix this problem?

cakephp pages not updating without browser refresh

I am working on a site using cakephp 2.10. It appears that the pages do not update unless the browser is refreshed. For example, I sign in as a user, it redirects me to the last page I was on before I left the previous time. (Correct function). But, when I go back to the main page, it shows me signed out. If I then refresh the page, it shows me signed in. I have tried clearing the files in the folders under app/tmp/cache/.... (persistent, model, etc) and I even tried turning debug to 3 to try and get the cache to refresh that way. I am baffled why this is working this way. Any thoughts would be appreciated. I have experienced this on three sites I am working on recently.

How to use the rehydration with mobx-persist

I am new to mobx-persist. I am not able to figure out how rehydration works in mobx-persist. I tried asking about it in github but got no reply so far. I am wondering if anyone here is able to point me the right direction.
The problem that I am trying to solve is to prevent losing the react states on the page refresh. I want to keep the stats in the session storage and load them back when the page is refreshed. (Note: I managed to do it by accessing the session storage directly from the react store but I thought that mobx-persist might do the better job.)
I created a sample here. https://github.com/michaelsync/js-lab/tree/master/mobx-persist-sample.
You can use the following command to run the sample.
yarn install
yarn start
It has two components called "entry" page and "result". User can enter something in "entry" page and show that data in the "result" page. There is one store called userDataStore that has only one property called data.
When you click on "Click Me" in the entry page, the data that you typed on text box will be saved in user data store. and it retrieves the data back from the result page.
The issue is that when I refresh the page, I still lost the react states. I guess it's because I don't understand how rehydration works in mobx-persist.
The steps to replicate the issue ~
run the program by using yarn start
enter something in textbox and click on "Click me" (It will redirect to the result page)
you will see what you entered in the result page.
Refresh the page (press F5) - the data will be lost.
Can someone please help me with the steps that I need to do in hydration and rehydration?
Note: I don't want to use any server-side code or isomorphic rendering to sync the states for now. using the session storage might be anti-pattern but I see it fit in my tiny project.

Preventing from part of files loading to browser

I am using angular
Lets say i have login screen(model,controller,view) and few other screens (model,controller,view) that perform some secret manipulation that available only to logged in user.
Is this possible to load to browser only login files(That those files won't be shown in F12/sources) ,then when user successfully logged in load all the secret files.
In short i don't want that user can see those files before he logged in.
That is one of the problems within client-side applications like angular SPAs. Since you want to load the content from your server, IF something happens on the client, the client already has to know, where it can get the content.
One solution could be to us ui-router. (Documentation). There, you can set a state for logged in users. Every state can have an own html template, which gets loaded, when you enter the state.
The problem ist, that the path of said html template is already on the client. That means, you have to set some kind of cookie from your server, so that you know, that the client is logged in. And only then, the requested template can be recieved. That way everybody can know where the template is on your server but cannot access it.

Resources