Sunday, August 11, 2019

node.js: flash: a req.session is required!



>PROBLEM


a req.session is required!
AssertionError [ERR_ASSERTION]: a req.session is required!
    at L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\flash\index.js:6:5
    at Layer.handle [as handle_request] (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:317:13)
    at L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:335:12)
    at next (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:275:10)
    at logger (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\morgan\index.js:144:5)
    at Layer.handle [as handle_request] (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:317:13)
    at L:\work\devcli_\javascript\node\projects\tellme4\tellme4\node_modules\express\lib\router\index.js:284:7


>SOLUTION

>>WRONG:

//*** wrong place of flash configuration, before session:

app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(session({
  secret: "fd34s@!@dfa453f3DF#$D&W",
  resave: false,
  saveUninitialized: true,
  cookie: { secure: !true }
}));


>>RIGHT:

app.use(passport.initialize());
app.use(passport.session());
app.use(session({
  secret: "fd34s@!@dfa453f3DF#$D&W",
  resave: false,
  saveUninitialized: true,
  cookie: { secure: !true }
}));
//*** right place after session:
app.use(flash());


>ENV
w10
node.js

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...