1

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.

2
  • 1
    Paste the contents of your jade file also please. Commented Dec 19, 2011 at 8:07
  • 1
    you dont need locals:{} anymore, just the key:vals inside it Commented Dec 19, 2011 at 8:43

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ay, I should've carefully looked over my jade file. Thanks for the help! I guess I'm not used to looking at jade syntax, though this is an obvious problem now that you point it out.
1

Maybe something is wrong with your sessions/new.jade view?

Comments

1

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 });
};

5 Comments

Made the change. Same SyntaxError occurs, except line number is now 6 (still the res.render line).
Then it's absolutely coming from your jade view file. My advice is to delete everything from the view, then add line by line and test (it's fast and easy since you only have a few lines in your view).
I just deleted all the lines in my new.jade file and got the same issue. Did the same with my layout.jade file (see edit to original post)
Perhaps it's better to paste your whole app's code (you can reduce your app so we can replicate this problem), put the code files somewhere online such as pastie.org
Yeah, that's a good idea (I tried to do this before by duplicating my app's directory structure into its public folder, but for some reason that didn't work.) See my third edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.