Create Auth Helper Function
auth.server.ts
Create ./app/utils/auth.server.ts
import { verifyAuthenticityToken } from "remix-utils";import { getSession } from "./sessions.server";export const getSessionData = async (request: Request,verifyCsrfToken = false) => {const session = await getSession(request.headers.get("cookie"));// Optionally validate CSRF tokens https://github.com/sergiodxa/remix-utils#verify-in-the-actionif (verifyCsrfToken) {// Check if the CSRF value in the Cookie matches the form value// https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookieawait verifyAuthenticityToken(request, session);}return {idToken: session.get("idToken") as string | undefined,csrf: session.get("csrf") as string | undefined,session,};};
Did you find this page helpful?
Start with GraphQL on Hasura for Free
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs