Sign up for Hasura Newsletter

Setup Auth in Remix

githubsessions.server.ts

Create ./app/utils/sessions.server.ts

import { createCookieSessionStorage } from "remix";
// Learn more about cookies at MDN https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
// With Firebase hosting your cookie must be named __session https://firebase.google.com/docs/hosting/manage-cache#using_cookies
const { getSession, commitSession, destroySession } =
createCookieSessionStorage({
cookie: {
name: "__session",
secrets: [process.env.COOKIE_SECRET!],
sameSite: "lax",
httpOnly: true,
secure: true,
path: "/",
// Set session expiration to 5 days
maxAge: 60 * 60 * 24 * 5,
},
});
export { getSession, commitSession, destroySession };

We have .server in the file name so the compiler knows we are only using this module server side

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2022 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin