Minimum Viable Auth Setup for PERN Stack
Steps for local deploy
In client directory:
npm install- Add and populate
.envat client root with appropriate values to connect to REST API npm run devto launch vite
In server directory
npm install- Add and populate
.envat server root to connect to database and specify where the server should listen npm run devto 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
Languages
JavaScript
92.9%
CSS
5.9%
HTML
1.2%