-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Description
I am trying to make this app. I am working on FBAuth function, but it doesn't work. Postman shows me {} as a response, and firebase logs shows:
Error while verifying token TypeError: Cannot read property 'data' of undefined
at FBAuth.admin.auth.verifyIdToken.then.then (/srv/index.js:71:46)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
My code looks like this:
const FBAuth = (req, res, next) => {
let idToken;
if (
req.headers.authorization &&
req.headers.authorization.startsWith('Bearer ')
) {
idToken = req.headers.authorization.split('Bearer ')[1];
} else {
console.error('No token found');
return res.status(403).json({ error: 'Unauthorized' });
}
admin.auth().verifyIdToken(idToken)
.then((decodedToken) => {
req.user = decodedToken;
return db
.collection('users')
.where('userId', '==', req.user.uid)
.limit(1)
.get();
}).then((data) => {
req.user.username = data.docs[0].data().username;
return next();
}).catch((err) => {
console.error('Error while verifying token ', err);
return res.status(403).json(err);
});
};
Can anybody help me?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels