Add session authentication

This commit is contained in:
Kevin Thomas
2021-07-29 22:24:39 -07:00
parent 2439fc8813
commit a9adbdc856
5 changed files with 10 additions and 18 deletions

View File

@@ -40,7 +40,6 @@ app.use(function (req, res, next) {
})
app.use(passport.initialize())
app.use(passport.authenticate('session'))
//app.use(passport.session());
// Define routes
app.use('/', indexRouter)

View File

@@ -39,14 +39,12 @@ module.exports = function () {
// serializing, and querying the user record by ID from the database when
// deserializing.
passport.serializeUser(function (user, cb) {
console.log('serializing user: ');
process.nextTick(function () {
cb(null, { id: user.id, username: user.username })
})
})
passport.deserializeUser(function (user, cb) {
console.log("DESERIALIZE")
process.nextTick(function () {
return cb(null, user)
})

View File

@@ -4,24 +4,14 @@ const passport = require('passport')
const router = express.Router()
router.post('/login/password', passport.authenticate('local'), function (req, res, next) {
console.log('login cookies: ', req.cookies)
console.log('login is authenticated: ', req.isAuthenticated())
console.log('/login/password req.user: ', req.user)
console.log('login session: ', req.session)
//res.json(req.user)
return res.send('You were authenticated & logged in!\n');
return res.send('Authenticated and logged in')
})
router.get('/auth', function (req, res) {
console.log('auth cookies: ', req.cookies)
console.log('in /auth')
console.log('auth is authenticated: ', req.isAuthenticated())
console.log('/auth req.user: ', req.user)
console.log('auth session: ', req.session)
if (req.user) {
res.status(200).end()
res.sendStatus(200)
} else {
res.status(401).end()
res.sendStatus(401)
}
})

View File

@@ -4,7 +4,12 @@ import router from './router'
import vuetify from './plugins/vuetify'
import Axios from 'axios'
Vue.prototype.$http = Axios
const instance = Axios.create({
baseURL: 'https://localhost:3000',
withCredentials: true
})
Vue.prototype.$http = instance
Vue.config.productionTip = false

View File

@@ -41,7 +41,7 @@ const router = new VueRouter({
})
router.beforeEach((to, from, next) => {
if (to.name === 'TMP_Home') {
if (to.name === 'Home') {
instance.get('/auth')
.then(response => {
if (response.status === 200) {