search and replace ```\n< with ```\n\n< to ensure there's an empty line before closing tags
4.0 KiB
4.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
5895f70cf9fc0f352b528e65 | Set up Passport | 2 | 设置护照 |
Description
"passport": "^0.3.2"
此外,现在还要将Express-session添加为依赖项。 Express-session拥有大量可以使用的高级功能,但现在我们只是要使用基础知识! "express-session": "^1.15.0"
您需要立即设置会话设置并初始化Passport。一定要先创建变量'session'和'passport',分别要求'express-session'和'passport'。要设置您要使用的快速应用程序使用会话,我们将仅定义几个基本选项。请务必将“SESSION_SECRET”添加到.env文件中,并为其提供随机值。这用于计算用于加密cookie的哈希值! app.use(会话({ secret:process.env.SESSION_SECRET, resave:是的, saveUninitialized:true, }));您也可以继续告诉您的快递应用程序使用 'passport.initialize()'和'passport.session()'。 (例如,
app.use(passport.initialize());
)当您认为自己正确时,请提交您的页面。如果您遇到错误,可以在这里查看到目前为止完成的项目。 Instructions
Tests
tests:
- text: Passort和Express-session是依赖项
testString: getUserInput => $.get(getUserInput('url')+ '/_api/package.json') .then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'passport', 'Your project should list "passport" as a dependency'); assert.property(packJson.dependencies, 'express-session', 'Your project should list "express-session" as a dependency'); }, xhr => { throw new Error(xhr.statusText); })
- text: 正确要求依赖性
testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /require.*("|')passport("|')/gi, 'You should have required passport'); assert.match(data, /require.*("|')express-session("|')/gi, 'You should have required express-session'); }, xhr => { throw new Error(xhr.statusText); })
- text: Express应用程序使用新的依赖项
testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /passport.initialize/gi, 'Your express app should use "passport.initialize()"'); assert.match(data, /passport.session/gi, 'Your express app should use "passport.session()"'); }, xhr => { throw new Error(xhr.statusText); })
- text: 正确设置会话和会话密钥
testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /secret:( |)process.env.SESSION_SECRET/gi, 'Your express app should have express-session set up with your secret as process.env.SESSION_SECRET'); }, xhr => { throw new Error(xhr.statusText); })
Challenge Seed
Solution
// solution required
/section>