-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangzhao
committed
Aug 2, 2018
1 parent
6dd5e53
commit 4df1342
Showing
8 changed files
with
164 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"env" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import express from 'express'; | ||
const router = express.Router(); | ||
|
||
// Transform req & res to have the same API as express | ||
// So we can use res.status() & res.json() | ||
var app = express(); | ||
router.use((req, res, next) => { | ||
Object.setPrototypeOf(req, app.request); | ||
Object.setPrototypeOf(res, app.response); | ||
req.res = res; | ||
res.req = req; | ||
next(); | ||
}); | ||
|
||
//Add POST - /api/login | ||
router.post('/login', (req, res) => { | ||
if (req.body.username == 'demo' && req.body.password == 'demo') { | ||
req.session.authUser = { username: req.body.username }; | ||
return res.json({ username: req.body.password }); | ||
} | ||
res.status(401).json({ message: "Bad credentials" }); | ||
}); | ||
|
||
router.post('/logout', (req, res) => { | ||
delete req.session.authUser; | ||
res.json({ ok: true }); | ||
}); | ||
//Export the server middleware | ||
export default { | ||
path: '/api', | ||
handler: router | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export default function ({ store, redirect }) { | ||
// console.log(store); | ||
// console.log(store.state); | ||
if (!store.state.authenticated) { | ||
if (!store.state.authUser) { | ||
return redirect('/login'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters