const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp()
const express = require('express');
const app = express();
const cors = require('cors');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt');
const initizalize = require('./passportConfig');
const bodyParser = require('body-parser')
app.use(bodyParser.json())
const cookieParser = require("cookie-parser");
app.use(cookieParser());
const db = admin.firestore()
app.get('/checkToken', function(req, res) {
console.log('Cookies: ', req.cookies.token);
res.sendStatus(200);
});
exports.app = functions.https.onRequest(app);
I can see on chrome dev tools that there is a token there but for some reason the token is undefined when the path /checktoken is called.
Try using credentials options in fetch options. Allowed values are 'same-origin' for same-origin requests, 'include' for all requests, 'omit' to omit the use of cookies. Fetch by default uses `'omit``. Docs
If you are using credentials: 'include', you must set the Access-Control-Allow-Origin header to * at the backend. If you are using cors module then simply do app.use(cors()), or app.use(cors({ origin: '*' })). Both are same.