I am having trouble implementing steam's authentication
server.js
app.prepare()
.then(() => {
const server = express()
server.use(session({
secret: 'foo',
resave: false,
saveUninitialized: true,
store: new MongoStore({ mongooseConnection: db })
}))
server.use(passport.initialize())
server.use(passport.session())
server.get('/logout', (req, res) => {
req.logout()
res.redirect('/')
})
server.get('/auth/steam',
passport.authenticate('steam', { failureRedirect: '/' }),
(req, res) => {
res.redirect('/')
})
server.get('/auth/steam/return',
passport.authenticate('steam', { failureRedirect: '/' }),
(req, res) => {
res.redirect('/')
})
server.get('/', (req, res) => {
return handle(req, res)
})
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on ' + address)
})
})
links like this one arent working while NODE_ENV=production
return <Link href='/auth/steam'><a>Conectarse con Steam</a></Link>
they redirect to http://localhost:3000/_next/pages/auth/steam instead of going throught
server.get('/auth/steam',
passport.authenticate('steam', { failureRedirect: '/' }),
(req, res) => {
res.redirect('/')
})
which would redirect to the steam authentification page and then redirect to '/' once it logs in
This is working while NODE_ENV isnt production
Link is for Client-side transitions using history.pushState. It looks you should use just <a/> in this case.
I tried that and is still not working
I should correct what i said about the environment, it isnt realated to that
It works if i use "node server.js" to start the app, it doesnt work if i use "npm start" which in package.json is "next start"
I did "next build" before trying to start
Heres the code for the links
import React from 'react'
export default class Footer extends React.Component {
render () {
if (this.props.user) {
return <a href="/logout">Desconectarse</a>
} else {
return <a href="/auth/steam">Conectarse con Steam</a>
}
}
}
You can't use next start if you have a custom server.
Its working now, i was using heroku to test it and its working there too
Thank you very much, this clears up a lot of things now