-
-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work at all #9
Comments
I have this on my app |
What am I doing wrong? require('dotenv').config()
const next = require('next')
const express = require('express')
const session = require('express-session')
const passport = require('passport')
const LocalStrategy = require('passport-local')
const uid = require('uid-safe')
const dev = process.env.NODE_ENV !== 'production'
const app = next({
dev,
dir: './src'
})
const nextHandle = app.getRequestHandler()
app.prepare().then(() => {
const server = express()
const sessionConfig = {
secret: uid.sync(18),
cookie: {
maxAge: 86400 * 1000 // 24 hours in milliseconds
},
resave: false,
saveUninitialized: true
}
server.use(session(sessionConfig))
passport.use(new LocalStrategy(function(username, password, done) {
console.log(`login ${username}:${password}`)
if (username === process.env.USERNAME && password === process.env.PASSWORD)
return done(null, {username})
done(null, false)
}))
passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser((user, done) => done(null, user))
server.use(passport.initialize())
server.use(passport.session())
const restrictAccess = (req, res, next) => {
if (!req.isAuthenticated()) return res.redirect('/login')
next()
}
server.post('/login', passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' }), (req, res) => {
res.redirect('/')
})
server.get('*', nextHandle)
server.listen(process.env.PORT)
}) |
For anyone else that runs into this issue, the Specifically adding the following line from the example resolved this issue for me: app.use(require('body-parser').urlencoded({ extended: true })); |
this make no sense already shown in code...... |
Yes the use of the |
Can someone link to the line in the repository? I can't find it edit: you can use:
instead of |
Hi, |
I am trying to use Passport (
v0.3.2
) andLocalStrategy
, I have copied the example code as is and it does not work at all.I am not getting any errors, but the page keeps loading
login
every time I hit "Submit".Putting
console.log()
inside the function that should find the users has no effect, seems that the function is never called.The headers:
The text was updated successfully, but these errors were encountered: