Exercise: Authentication & Authorization
Using: Node.js, Express, MariaDB, Vue2, vue-router, Objection/Knex, Axios, cookie-parser, JSON Web Tokens (JWT), and Bcrypt.
Register a new account
Log in to your account
Update your user profile (form submission)
Log out of your account
Examples of custom RESTful APIs built with Node.js and Express:
router . post ( '/register' , async ( req , res ) => {
router . get ( '/get/user/:id/public' , requireSession , async ( req , res ) => {
Examples of database interaction performed using Objection with Knex:
async function getUserPets ( id ) {
async function doRegisterUser ( formData ) {
Examples of managing authentication sessions using JSON Web Tokens (JWT):
function createToken ( id ) {
async function requireSession ( req , res , next ) {
async function validateSession ( session ) {
Examples of hashing passwords using Bcrypt:
async function createHash ( password ) {
async function doBcryptCompare ( id , password ) {
hashedPassword : await createHash ( formData . password ) ,
Examples of protecting application routes using navigation guards with vue-router:
async function findExistingSession ( to , from , next ) {
async function guardBehindSession ( to , from , next ) {
beforeEnter : findExistingSession ,
beforeEnter : guardBehindSession
const session = await axios .get (' /api/get/cookie' ).then ((result ) => { return result; }).catch ((error ) => { throw error; });
Examples of handling form submission data using Vue2 (Options API) and Axios: