This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Botstrap Start": { | |
| "prefix": "!start", | |
| "body": [ | |
| "<!doctype html>", | |
| "<html lang=\"en\">", | |
| "<head>", | |
| "<meta charset=\"utf-8\">", | |
| "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">", | |
| "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const cookieParser = require('cookie-parser') | |
| const app = express(); | |
| app.use(express.json()) | |
| app.use(cookieParser()) | |
| app.get('/', (req, res) => { | |
| res.send('Welcome to my API') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const jwt = require('jsonwebtoken'); | |
| function generateToken(payload) { | |
| const token = jwt.sign(payload, 'mySecretKey'); | |
| return token; | |
| } | |
| function isLoggedIn(req, res, next) { | |
| // Check if the user has token in cookies. If not return the request; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const cookieParser = require('cookie-parser') | |
| const app = express(); | |
| // Import auth.js that we created earlier | |
| const auth = require('./auth'); | |
| app.use(express.json()) | |
| app.use(cookieParser()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/profile', auth.isLoggedIn, (req, res) => { | |
| res.send(`Hello ${req.user.name}`); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const app = express(); | |
| app.get('/', (req, res) => { | |
| if(req.isAuthenticated()){ | |
| res.send(`Heyyyy ${req.user.email}`) | |
| }else{ | |
| res.send('Whooo Areee youuuuuu ???') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const passport = require('passport'); | |
| const session = require('express-session'); | |
| const app = express(); | |
| app.use(session({ secret: 'mysecret', resave: true, saveUninitialized: true })); | |
| app.use(passport.initialize()) | |
| app.use(passport.session()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const LocalStrategy = require('passport-local').Strategy; | |
| module.exports = function(passport){ | |
| passport.use( | |
| new LocalStrategy({usernameField: 'email', passwordField: 'password'}, (email, password, done) => { | |
| // ... do the database stuff with email and passsword and get all the details | |
| // of user. In this case I am hardcoding the user. | |
| const user = { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const passport = require('passport'); | |
| const session = require('express-session'); | |
| const app = express(); | |
| // Configure the Passport JS | |
| require('./passport')(passport); | |
| app.use(session({ secret: 'mysecret', resave: true, saveUninitialized: true })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/login', passport.authenticate('local'), (req, res) => { | |
| res.send('Login Success') | |
| }) |