Work in progress on subscriptions
This commit is contained in:
parent
eecb3cd067
commit
b22a87e712
18 changed files with 1729 additions and 884 deletions
|
@ -42,6 +42,38 @@ module.exports.loggedIn = (req, res, next) => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports.authByAccessToken = (req, res, next) => {
|
||||
nodeifyPromise((async () => {
|
||||
if (!req.query.access_token) {
|
||||
res.status(403);
|
||||
return res.json({
|
||||
error: 'Missing access_token',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await users.getByAccessToken(req.query.access_token);
|
||||
req.user = user;
|
||||
next();
|
||||
} catch (err) {
|
||||
if (err instanceof interoperableErrors.NotFoundError) {
|
||||
res.status(403);
|
||||
return res.json({
|
||||
error: 'Invalid or expired access_token',
|
||||
data: []
|
||||
});
|
||||
} else {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
}
|
||||
})(), next);
|
||||
};
|
||||
|
||||
module.exports.setup = app => {
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue