-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving dev time by using JWT local and Session Cookies production #3
Comments
I'm planning on integrating this with cookiecutter-django... maybe if it's approved that is. Unfortunately, that might put a lot of maintainability issues on browniebroke, so may not. I may just create a template repository; however, I really love the layout of cookiecutter-django. Perhaps another tutorial would be helpful. The problem I see is that when you integrate JWT, you'll need to add some React components to the login page to handle everything. Everyone's login page is different... maybe we can add some JS code that works for everyone! Eh tbh, the only thing the developer needs to do is save the JWT in a non-httpOnly-flagged cookie. Maybe just add that into the tutorial instead. However, if this is the case, then I may need to create a new repository as this repository is not necessary anymore. The only thing we can takeaway from this repository would be that GitHub action to deploy, but even that is not truly necessary since according to @stunaz, many people split their frontend repo with their backend. I think that's game plan. Let's make a middleware that handle
|
The only concern now is build/index.html. I have no idea if that changes. We also have to transfer build/index.html to the backend repository if we're dealing with two repositories... Which is the whole reason why I had this in one repository to begin with. Edit: Ah they do.... I forgot about the manifest/hashes in the links and scripts |
We can do the same method we did for the static files: reply to GitHub. In the same GitHub action, we can determine a server repository, and using the same build, transfer our index.html file to our backend repository. Wherever your template repository is, it'll always include |
What I'm going to do is use SimpleJWT's template repository for React but also include the showing of DEBUG vs. RELEASE mode via the JS... if that makes sense. What you can do is in your index.html file, include a context variable from settings specifying if (JSON.parse(document.getElementById("debug")).data) {
// 1. Show a login form so that your JS can collect inputs via event listeners (as in <form action="." method="post" onsubmit="loginSubmit()"></form>)
// 2. authenticate via SimpleJWT by saving token in cookies
} else {
/*
1. Show a login form that actually does a POST request to the server. This means the user actually does the submission, not your form (as in <form action="ACTUAL URL" method="post"></form>)
2. The trick to know whether your user failed to submit login details/failed to authenticate is to quickly set in your sessionStorage whether you were on the login page. When your SPA reloads, just read your sessionStorage to see and load accordingly. Your web page automatically reloads because the "form" tag does the post request for you. When your web page reloads, the server has set the HTTPOnly cookie.
*/
} |
@dgmouris @loicgasser The above is how we should implement the template repositories. |
Copied from here
Since I've never used a JS framework before, I have zero clue what the ramifications are regarding constantly rebuilding the app... In the following, I'm proposing a middleware that acts as a replacement for SessionMiddleware such that your JWT token and Session cookies during DEBUG=True and False, respectively, and are set on request.session.
The reasons being is that we want to take advantage of React reloading a lot faster than rebuilding. Anyways, the original quote:
The text was updated successfully, but these errors were encountered: