Skip to content

Team Tips & Tricks

kairality edited this page Apr 14, 2022 · 1 revision

Fetch w/ CSRF Protection

Our project has a lot of fetching. CSRF protection with fetch is moderately annoying, so we built a utility wrapper called fetchWithToken that hides some of the syntax and makes it cleaner. To use it:

  1. At the top of your file import the /public/javascripts/utils.js file. If you are in the /public/javascripts/ folder the syntax looks like this
import { fetchWithToken } from "/utils.js"

Note that you cannot use common JS module syntax in these files ("require") and the .js extension IS required. To use fetchWithToken you just pass in the URI, the method, and the JSON stringified body of your fetch request. The wrapper will construct all the headers and parameter objects for you and you canawaitit or use it in a Promise chain just like you would use fetch.

Pull / Rebase Workflow

  1. Create a new branch for every feature by git branch my_feature_here or git checkout -b my_feature_here. The latter is a shortcut to create the branch and switch at the same time. Where possible, you should create your branch on a freshly pulled main
  2. Complete your feature / fix, commit your changes with git commit -m "this message should be useful and describe what you did
  3. git checkout main
  4. git pull main
  5. Switch back to your feature branch with git checkout my_feature_here
  6. git rebase main
  7. Resolve any merge conflicts. Ask for help if you need it! This step is important! When you're done, git add the changes and git rebase --continue
  8. Push your code and there should be no merge conflicts with the remote ** main**

This flow is very important because it helps keep a clean history and reduces the chance of accidentally clobbering important changes. Please do it every time!

Uh-oh, I committed on main!

It happens! Don't panic! If it was just one commit:

  1. git branch a_new_branch_name_here. Note we did NOT checkout the branch. Don't use the shortcut.
  2. git reset HEAD~1 This will move main back before your stray commit.
  3. git checkout a_new_branch_name_here Checkout the new branch you made. Your commit is there and you can continue working/push your work.

If you made multiple commits you will need to add an extra step between 1 and 2 where you use git log to see how many commits back you need to rewind.

Clone this wiki locally