Created
November 23, 2015 16:53
-
-
Save shadow7/cf7c7d7e7f19d0f93107 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Ensure authorization with firebase before requesting any data. | |
| * @param req request | |
| * @param res response | |
| * @param next call next | |
| */ | |
| middleware.ensureAuthenticated = function (req, res, next) { | |
| var authToken = req.query.auth; | |
| if (authToken == null) { | |
| console.log("Null firebase token"); | |
| return res.status(401).send("401 required query param \"auth\" missing"); | |
| } | |
| middleware.store.authWithCustomToken(authToken, function (error, authData) { | |
| if (error) { | |
| console.log("Authentication Failed!", error); | |
| res.status(401).send("Error authenticating with Firebase: ", error); | |
| //THIS IS WHERE WE BLOW UP | |
| next(error); | |
| } else { | |
| console.log("Authenticated successfully with payload: ", authData); | |
| return next() | |
| } | |
| }); | |
| }; | |
| //I'm assuming since ensureAuthenticated never calls next, this is actually whats failing and causing android to get | |
| //Error retrofit.RetrofitError: 503 Service Unavailable. | |
| router.get("/", middleware.ensureAuthenticated, userMiddleware.getUsers); | |
| // production error handler | |
| // next(error should end up here) | |
| app.use(function(err, req, res, next) { | |
| res.status(err.status || 500); | |
| res.render('error', { | |
| message: err.message, | |
| error: {} | |
| }); | |
| rollbar.reportMessage(err); | |
| next(err); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment