I have been facing this issue for weeks now, am trying to login to my app on IOS device, it turns out that express-session did not store cookies in the browser, for this reason, I was unable to login. But I was able to login on my android device and laptop. But am still unable to access the app on safari on my android device.
My frontend stack is Nextjs, and Nodejs with express for my backend.
Backend was deployed on heroku and frontend was deployed on netlify
Pls how do I solve this problem. Here is what my code looks like.
============================Server.js=====================================
import express from "express"
import rootRoute from "./src/root_Route.js"
import cookieParser from "cookie-parser"
import passport from "passport"
import connectPgSimple from "connect-pg-simple"
import session from "express-session"
import dotenv from "dotenv"
import cors from "cors"
import "./src/LIB/DB-Client.js"
import "./src/PASSPORT_STRATEGY/google-auth-strategy.js"
import "./src/PASSPORT_STRATEGY/facebook-auth-strategy.js"
import { scheduleJob } from "node-schedule"
import pool from "./src/LIB/DB-Client.js"
dotenv.config()
const app = express()
const connection = process.env.PRODUCTION !== "production" ? process.env.DEV_DATABASE_URL : process.env.DATABASE_URL
app.use(
cors({
origin: ["http://localhost:3000", "https://nairaonly-frontend.netlify.app"],
credentials: true,
methods: "GET, PUT, POST, DELETE",
optionsSuccessStatus: 200,
})
)
const PgStore = connectPgSimple(session)
const store = new PgStore({ conString: connection, schemaName: "hidden", createTableIfMissing: true })
app.use(express.json())
app.use(cookieParser())
app.set("trust proxy", 1)
app.use(
session({
store: store,
secret: process.env.SESSION_SECRET,
saveUninitialized: false,
resave: true,
proxy: true,
cookie: {
maxAge: 1000 * 60 * 60 * 24,
httpOnly: true,
sameSite: process.env.NODE_ENV === "production" ? 'none' : 'lax',
secure: process.env.NODE_ENV === "production" ? true : false,
},
})
)
app.get("/", (req, res) => {
res.send("API Running...")
})
app.use(passport.initialize())
app.use(passport.session())
rootRoute(app)
const PORT = process.env.PORT || 4000
app.listen(PORT, (req, res) => console.log(`Server running on PORT:${PORT}...`))
I have been facing this issue for weeks now, am trying to login to my app on IOS device, it turns out that express-session did not store cookies in the browser, for this reason, I was unable to login. But I was able to login on my android device and laptop. But am still unable to access the app on safari on my android device.
My frontend stack is Nextjs, and Nodejs with express for my backend.
Backend was deployed on heroku and frontend was deployed on netlify
Pls how do I solve this problem. Here is what my code looks like.
============================Server.js=====================================