-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hi,
I am using firebaseauth version ^1.0.0. I am getting an issue and not able to resolve. I am using firebase auth to authenticate users to use my endpoints. while using I am getting an error UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'callback' of undefined
at node_modules/firebaseauth/dist/middlewares/guard.js:68:26.
I am getting this error when token is valid
Kindly guide me
my code
const middlewareCallback = function(req, res, next, error, data) {
if (error === 'ERROR_NO_TOKEN') {
// token not supplied
res.status(401).json({error: "No token provided"});
}
else if (error === 'ERROR_INVALID_TOKEN') {
// token failed verification
res.status(401).json({error: "Unauthorized access"});
}
else if (error) {
// some other error occurred (this should never happen!)
res.status(500).json({error: "Unexpected error"});
}
else if (data.error) {
// there was no error with verifying the token, thus user id can be found in data.userId
// there was however an error in getting user info from firebase using the id
res.status(401).json({error: "An error occurred while trying to verify your credentials"});
}
else {
// data contains user id and token (v0.2.0 and later) and full user information (id, displayName, email etc) for v0.1.1 and earlier
req.user = data;
next();
}
};
const options = {
tokenField: "key",
userIdOnly: false
};
const firebaseTokenMiddleware = FirebaseAuth.initTokenMiddleware(serviceAccount, options);
app.use(firebaseTokenMiddleware)