02/06/2020 - passportjs | JAMstack, graphQL
passport js - user athentification
- passport allows 3rd party auth in express = good user experience, no password proliferation, no storing of user passwords in database
- is a combination of middleware
- below is the code sandbox for passport js.
- i am following net ninja's tutorial. see here
- i am using google, facebook and local strategies,
- in the set up code, need to go to the google and facebook developers api console to create the client keys and secrets
- code sandbox allows users using node templates to have secret keys and reference with process.env, these are private and not copied over when forked
- added some logic in the routes to check if the user email existed and also user account integration if the auth method was used to login before
- schema structure: mongo recommends embedding, vs ref
- not yet done the local - sign up (not included in passport) + login, will need to use bcryptjs to hash the stored password
jamstack
- #webdev, #jamstack
- saw this new way of doing things called the JAMstack.
- aint a specific technology stack
- basically you convert your code into static files and serve via cdns and not servers
- serverless = no more server errors
- the stack i want to learn is gatsby/graphql + netlify + contentful
- then i will ponder about how to do the auth routes
- you combine with netlify to push deployment easy and a headless CMS like contentful to update your site data
- get a really easy way of creating and maintaining a website
- i went to learn graphql - youtube: netninja - graphql, you can visit the github repo here
- the technologies are node, express, react, graphql, apollo
- because i have heard good reviews about it
- graphql = query language for apis
- just like sql = query language for relational databases
- no more writing crud routes in express for every single collection of data. yay.
codes
- codesandbox for the front end, backend is at the bottom, i couldn't be bothered to copy paste the front end react template + configure the npm scripts, just so the both runs on the same sandbox,so i just referenced another sandbox for the backend + used cors middleware
- youtube netninjs - check out his tutorials, he is a good teacher
- frontend
- codesandbox backend - i am using the /graphql route as the api endpoint
- advantages:
- cut out express crud routes - get post put delete etc
- no more mongo embed or refs, no more mongo queries (no more callback hell or thenables)
- clean data structure super easy to parse into the react front end
Comments