Mikayla Dobson 38f8ef23d0 readme
2023-02-02 17:38:31 -06:00
2023-02-02 17:23:10 -06:00
2023-02-02 17:33:34 -06:00
2023-02-02 17:38:31 -06:00

Minimum Viable Auth Setup for PERN Stack


Steps for local deploy

In client directory:

  1. npm install
  2. Add and populate .env at client root with appropriate values to connect to REST API
  3. npm run dev to launch vite

In server directory

  1. npm install
  2. Add and populate .env at server root to connect to database and specify where the server should listen
  3. npm run dev to launch development server with nodemon

Steps to extend

The following middleware (taken from server/routes/index.js) can be used anywhere user verification is needed:

app.use('/app', (req, res, next) => {
    const token = req.headers['authorization'].split(" ")[1];
    jwt.verify(token, process.env.SECRET, (err, data) => {
        if (err) {
            res.status(403).send(err);
        } else {
            req.user = data;
            next();
        }
    })
})

Additional passport strategies may also be included for auth workflows such as OAuth 2.0

Description
Simple implementation of an auth setup with React, Express.js, and PostgreSQL
Readme 61 KiB
Languages
JavaScript 92.9%
CSS 5.9%
HTML 1.2%