Reputation: 2227
So I'm trying to follow this tutorial video:
http://nodetuts.com/tutorials/13-authentication-in-express-sessions-and-route-middleware.html#video
and as such I've got this code at the top of my routes/index.js
file:
var todo = require('../todo'); //line 1
//line 2
//new session //line 3
exports.newSession = function (req, res) { //line 4
res.render('sessions/new', { //**line 5**
locals: {
redir: req.query.redir
}
});
};
but, when I run my app and trigger the routes.newSession
handler, I get this error:
500 SyntaxError: Unexpected identifier
at Object.Function (unknown source)
at Object.compile (/home/admin73464/todo/node_modules/jade/lib/jade.js:161:8)
at Function.compile (/home/admin73464/todo/node_modules/express/lib/view.js:65:33)
at ServerResponse._render (/home/admin73464/todo/node_modules/express/lib/view.js:414:18)
at ServerResponse.render (/home/admin73464/todo/node_modules/express/lib/view.js:315:17)
at /home/admin73464/todo/routes/index.js:5:6
at callbacks (/home/admin73464/todo/node_modules/express/lib/router/index.js:272:11)
at param (/home/admin73464/todo/node_modules/express/lib/router/index.js:246:11)
at pass (/home/admin73464/todo/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/home/admin73464/todo/node_modules/express/lib/router/index.js:280:4)
I don't see any syntax errors in my index.js
file; do you? Should I be looking somewhere else?
Thanks in advance!
EDIT: here are the contents of my views/sessions/new.jade file:
h1 Login
form(action='/sessions', method='POST')
input(type='hidden', name='redir', value=redir)
p
label(for='login') Login:
input(type='text' name='login', id='login')
p
label(for='password') Password:
input(type='password' name='password', id='password')
p
input(type='submit')
I'm pretty sure I copied exactly what Pedro wrote.
SECOND EDIT: I'm also using a layout.jade file. Here it is:
!!!
html
head
title Our ToDo App
link(rel='stylesheet', href='/stylesheets/style.css')
body!= body
Per a respondent's suggestion, I've tried deleting all (and all but the first) lines from new.jade. I got the same error. I've also tried deleting all the lines from layout.jade, and also deleting only the last line (body!= body). Same error.
Thanks for all the responses so far, I'm so glad for the help and suggestions you've given me so far.
THIRD EDIT: I've posted my app's folder and files at
http://www.miramontestequila.com/todo/
The directory structure I'm using is Express's default, and should thus be self-explanatory.
Upvotes: 1
Views: 3720
Reputation: 18205
In your new.jade
file, you have the lines
input(type='text' name='login', id='login')
input(type='password' name='password', id='password')
You're missing commas between type
and name
attributes. Remember, in Jade, you must put commas inbetween HTML attributes.
Upvotes: 8
Reputation: 63663
Can you change the contents of index.js like so and tell me if this fixes things:
exports.newSession = function (req, res) {
var redir = (req.query && req.query.redir) || '';
res.render('sessions/new', { redir: redir });
};
Upvotes: 1