Home > database >  I cant access a JWT token from a get request in express
I cant access a JWT token from a get request in express

Time:01-12

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);

Example Image of Error

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.

CodePudding user response:

Try using credentials options in fetch options. Allowed values are 'same-origin' for same origin requests, 'include' for all requests, 'omit' to omit use of cookies. Fetch by default uses `'omit``. Docs

  •  Tags:  
  • Related