Hey!
I’ve been pulling my hairs out for a couple hours to try to make capacitor.js works with my Node.js back-end but it seems like there is an issue with cookies:
I have a basic index.html in capacitor, and this as a back-end:
(Express + MongoDB + Passport)
const session = require("cookie-session")
const app = express()
app.use(passport.initialize());
app.use(passport.session());
// other code to setup express, passport etc
app.post("/validate-auth-code", async (req, res) => {
const user = await User.findOne({ email: 'myemail@email.com' })
if (!user) return res.status(404).send('User not found')
req.logIn(user, (err) => { })
console.log(req.user?.email);
res.send(user?.email)
})
app.post('/test-user', async (req, res) => {
console.log(req.user);
})
When I try this in a browser, it works fine, the session is saved and /test-user show the user.
However, when I send it from capacitor localhost:3000 to /test-user, it shows “undefined”.
/validate-auth-code show the user email and the user being logged in, so the issue seems to be that capacitor is not saving cookies
Am I missing something? How can I save the cookies in capacitor.js ?
(the HTML is just a blank page with a h1 and a fetch request in a script)
Sorry if this is a stupid question, I just started using capacitor a couple of hours ago, I’m really struggling with this.