mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-15 20:48:03 +00:00
Add session authentication
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user