Skip to content
\n

Troubleshooting Steps

\n

I’ve checked several common cross-origin and SameSite-related issues, including:

\n
    \n
  • Confirming that both frontend and backend are served over HTTPS.
  • \n
  • Setting SameSite: \"None\" and secure: true as required for cross-origin cookies.
  • \n
  • Inspecting browser Developer Tools, where I see the cookie is set initially but then removed or not available after reload.
  • \n
\n

Providing index.ts file as it maybe caused due to my project setup.

\n
import { Hono } from \"hono\";\nimport taskRoutes from \"./routes/taskRoutes\";\nimport noteRoutes from \"./routes/noteRoutes\";\nimport userRoutes from \"./routes/userRoutes\";\nimport authRoutes from \"./routes/authRoutes\";\nimport { updateTasksByDay } from \"./controllers/taskController\";\nimport { checkAuth } from \"./middlewares/checkAuth\";\nimport { cors } from \"hono/cors\";\nimport { secureHeaders } from \"hono/secure-headers\";\nimport { prettyJSON } from \"hono/pretty-json\";\n\ntype Bindings = {\n  DB: D1Database;\n  SECRET_KEY: string;\n  FRONT_END_URL: string;\n};\n\nconst app = new Hono<{ Bindings: Bindings }>();\n\napp.use(\"*\", async (c, next) => {\n  c.header(\"Access-Control-Allow-Origin\", c.env.FRONT_END_URL);\n  c.header(\"Access-Control-Allow-Methods\", \"GET, POST, PUT, DELETE, OPTIONS\");\n  c.header(\"Access-Control-Allow-Headers\", \"Content-Type, Authorization\");\n  c.header(\"Access-Control-Allow-Credentials\", \"true\");\n  if (c.req.method === \"OPTIONS\") {\n    return c.text(\"\", 204);\n  }\n\n  await next();\n});\n\napp.use(secureHeaders());\napp.use(prettyJSON());\n\napp.use(\"/api/tasks/*\", checkAuth);\napp.use(\"/api/notes/*\", checkAuth);\n\napp.route(\"/api/tasks\", taskRoutes);\napp.route(\"/api/notes\", noteRoutes);\napp.route(\"/api/users\", userRoutes);\napp.route(\"/auth\", authRoutes);\n\napp.get(\"/\", (c) => {\n  return c.html(`<a href=\"https://routine-lemon.vercel.app/routine\">UI</a>`);\n});\n\nexport default {\n  async fetch(request: Request, env: Bindings, ctx: ExecutionContext) {\n    return app.fetch(request, env, ctx);\n  },\n  async scheduled(event: ScheduledEvent, env: Bindings, ctx: ExecutionContext) {\n    ctx.waitUntil(updateTasksByDay(env.DB));\n  },\n};
","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Used firebase auth for session management to fix this Issue.
\nSayedTahsin/Routine-Vue@e88902e
\nAs we cannot set cookies from different domain. Frontend & Backend domain must be same.

","upvoteCount":1,"url":"https://github.com/orgs/honojs/discussions/3669#discussioncomment-11675091"}}}

Browser Deleting Cookies on Refresh. #3669

Answered by SayedTahsin
SayedTahsin asked this question in Q&A
Discussion options

You must be logged in to vote

Used firebase auth for session management to fix this Issue.
SayedTahsin/Routine-Vue@e88902e
As we cannot set cookies from different domain. Frontend & Backend domain must be same.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SayedTahsin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant