Programming

Sorry that wasn’t clear. It’s not making an ajax auth request - it’s basically checking localStorage. But for some reason amplify makes it an async function.

But anyway once I do this async Auth.getSession() call to determine logged in state and get the initials to show in the header - can you just give me a super high-level of how you would store that in global state and have the header component watching it? Does global state just live in App.js, where our BrowserRouter routes live?

The moderators of this message board, otatop, L.Washington, WichitaDM, Yuv, JonnyA, RiskyFlush, and SvenO, are cowards who let abusers dox and harrass other long time posters.

Yeah I guess that’s the problem - the header component is part of the page component, which we have a dozen or so declared as routes in App.js. But right now we’re passing a function down to the page to call after login is confirmed - LOL.

It might still be a big improvement to just pass props that get updated every time App.js state changes - instead of a function the page has to explicitly call. Incremental change.

Also we’re using context a lot in site #2. I can probably figure it out from those examples.

No fighting in the programming thread please.

I thought the header was in the page but actually it isn’t. This can’t be that hard. The only problem left is to somehow set the authenticatedUser in App.js state from our custom-redux-like login helper thing. But I think I can figure that out.

The moderators of this message board, otatop, L.Washington, WichitaDM, Yuv, JonnyA, RiskyFlush, and SvenO, are cowards who let abusers dox and harrass other long time posters.

This is site #1. Site #2 is the one that uses all the hooks.

Speaking of clueless code. This checkbox doesn’t keep you logged in and doesn’t stay checked. Total fail.

Redux doesn’t actually function any differently than just passing props down through components does it? (never used redux, but have passed props through components (and tried to make it easy enough to follow))

The moderators of this message board, otatop, L.Washington, WichitaDM, Yuv, JonnyA, RiskyFlush, and SvenO, are cowards who let abusers dox and harrass other long time posters.

Yep, we should have gone with redux from the beginning. Which was the plan. But my boss somehow hired a contractor who did the equivalent of maybe 2 weeks work from a good dev in the entire 6 months of his contract. I had to redo most of his stuff. Should have done it then.

I think you’re saying “yes” to this, but I mean literally, under the hood, that’s what it’s doing. You’re putting some code in every component that includes redux and passes along a redux object that holds all your global state? Like, you can just have a global state object and pass it everywhere on your own and it would be the same at the surface and under the hood and probably without some unneeded bloat.

?

In one of the apps I did, I just had a user class and passed the user object to everything so every component knew what it needed to know about a logged in user.

The moderators of this message board, otatop, L.Washington, WichitaDM, Yuv, JonnyA, RiskyFlush, and SvenO, are cowards who let abusers dox and harrass other long time posters.

Well, I haven’t been doing react lately. On the one hand it doesn’t seem like it would be hard to do what redux is doing, either by including something in each component or passing props to it. On the other hand, I’m sure redux must be implemented pretty well and in a way that makes things easier or so many people wouldn’t like it.

The code for redux isn’t all that intimidating ( GitHub - reduxjs/react-redux: Official React bindings for Redux ).

I have a Django application where the backend needs to pass some data to the frontend where it will be accessible to the frontend JS. My current method for doing this is to put the data into an inline script that parses a JSON literal and assigns it to the window object. I am pretty sure this is actually safe, but I feel a little nervous about this method either creating an XSS vulnerability or drawing questions from customers about why it’s not an XSS vulnerability.

Is the standard solution here to just fetch the data as soon as the page loads, and then deal with the possibility of the data not arriving by the time it’s needed (i.e., render the relevant component in a loading state or whatever). Is it viable/worthwhile/a good idea to do something with service workers so that the html and the data can be delivered together, and then the page can instantly ‘fetch’ it from the SW?

Are you using the REST framework? I’d expect the serializers to be secure by default.

The moderators of this message board, otatop, L.Washington, WichitaDM, Yuv, JonnyA, RiskyFlush, and SvenO, are cowards who let abusers dox and harrass other long time posters.

1 Like

I was just interested and googling stuff and found this…probably nothing you don’t know, but…

1 Like

This is just a regular template. I think it is XSS-safe by default, but I have to opt-out of the string sanitizing so that all the quotes in the JSON don’t get HTML-escaped.

So, some of the JSON values would be provided by the user, and it’s all going inside a tag. But as long as the JSON literal is wrapped in single quotes, anything malicious would have to escape the single quotes first, but those will all be escaped by the JSON encoder, so there can’t be a problem. Right?