I'm trying to use SailsJs to make a simple authentication web app with PassportJs + EJS template engine.
This is my code in the AuthenController.coffee
processSignin: (req, res) ->
passport.authenticate('local', (err, user, info) ->
if err or not user
return res.view('auth/signin', message:'failed')
req.logIn user, (err) ->
return res.view('auth/signin', message:'failed') if err
res.redirect '/'
) req, res
return
If I use: res.render('/auth/login', { message:'err' })
the browser only return HTML code of the login.ejs
If I use: res.view('/auth/login', { message:'err' })
then it return login.ejs code wrapped in the layout.ejs's <%-body%>
Any explanation for this different? Is it a new feature of Sails or built-in of Express? Where I can find documents about this?
res.render
is an expressJS method, while res.view
is a SailsJs method. The latter wraps the requested view in the default layout unless a different layout is requested. So you'll have to decide whether you want just the compiled template you're requesting (res.render
) or the more complete view (res.view
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With