-
run
npm run watchthis will compile the api typescript code into a folder called dist using webpack -
run
npm run devto start the server
To ssh into the db thats hosted on postgres run this command (find the values in heroku > rubber-ducker > settings > database credentials)
psql --host= --port=5432 --username= --password --dbname=
To run a migration ssh into the db using the above command then run
psql \i api/src/migrations/reviews.sql
-
using a package called
passportalong withpassport-githubto help with the authentication logic. -
the first method is
passport.serializeUserwhich takes the user object serializes it and attaches the user back onto thereqobjectreq.session.passport.user -
access this url
http://localhost:3002/auth/githubthepassport.authenticatemethod will prompt github to open an authentication window in the browser once you login a new startgy will be called and the third argument passed in is the profile of the user that just logged in. I am then checking theprofile.idagainst the github_id column in the postgres db. If no row is returned then im updating the db with the new users data. Once the update is complete thedonecallback function is called and creates a jwt accesToken once authenticated you are directed to/auth/github/callbackwhich gets the accessToken from the req and redirects the user tohttp://localhost:54321/auth/${req.user.accessToken}. When the user clicks on the login button in the extension UI I spin up a polka server which is listening on port54321. This fileextension/src/authenticate.tsthen takes the accessToken out of the paramas and saves it in the global state of the extension. This access token is then added to subsequent requests to the backend so that we know the request is coming from an authorized user. -
the
/meroute gets the accessToken from the header which will be attached to the authorization headers from the UI since we have stored the access token in the global state. Once I have checked the auth header exists and there is a token I then decode the accessToken usingjwt.verifymethod. In this fileapi/src/utils/authenticateUser.tswhen I calljwt.sign()I pass in the userId =user.github_idthis means that we can then use theuserIdthats returned to look up the user in the db and return the profile
- set env vars using
heroku config:set JWT_SECRET=XXX