Skip to content
Permalink
Browse files

first commit

  • Loading branch information
SinghDigamber committed Oct 12, 2019
0 parents commit 71c61a1bb2fc67a78ec83dcf6f0916d0aae345c5
Showing 2,766 changed files with 339,198 additions and 0 deletions.
BIN +6 KB .DS_Store
Binary file not shown.
@@ -0,0 +1,32 @@
# node-token-based-authentication

Node Token-based Authentication REST APIs tutorial with examples - learn how to build a secure user authentication CRUD APIs using JSON web token.


## Written Article
[Build Secure (JWT) Token Based Authentication API with Node](https://www.positronx.io/build-secure-jwt-token-based-authentication-api-with-node/)


## Authentication REST APIs
⋅⋅* GET (users list) **/api**
⋅⋅* POST (sign-in) **/api/signin**
⋅⋅* POST (sign-up) **/api/register-user**
⋅⋅* GET (user profile) **/api/user-profile/id**
⋅⋅* PUT (update user) **/api/update-user/id**
⋅⋅* DELETE (delete user) **/api/delete-user/id**


### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:4000/api](http://localhost:4000/api) to view it on the browser.


### Start Node Server

- Run `npm install` to install required packages
- Open terminal run `nodemon`
- Open other terminal run `mongod`

Open API URL on [http://localhost:4000/api](http://localhost:4000/api)# react-multiple-files-upload

@@ -0,0 +1,3 @@
module.exports = {
db: 'mongodb://localhost:27017/meanauthdb'
}
@@ -0,0 +1,13 @@
// middlewares/auth.js

const jwt = require("jsonwebtoken");

module.exports = (req, res, next) => {
try {
const token = req.headers.authorization.split(" ")[1];
jwt.verify(token, "longer-secret-is-better");
next();
} catch (error) {
res.status(401).json({ message: "No token provided" });
}
};
@@ -0,0 +1,23 @@
// models/User.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const uniqueValidator = require('mongoose-unique-validator');

let userSchema = new Schema({
name: {
type: String
},
email: {
type: String,
unique: true
},
password: {
type: String
}
}, {
collection: 'users'
})

userSchema.plugin(uniqueValidator, { message: 'Email already in use.' });
module.exports = mongoose.model('User', userSchema)

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 71c61a1

Please sign in to comment.
You can’t perform that action at this time.