From e4d4069aa87b9f4b5aa3d9a72e4e155105736aa3 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Mon, 20 May 2024 12:12:07 +0700 Subject: [PATCH] Add check for document in useCsrfToken hook This commit introduces a check for the existence of 'document' in 'useCsrfToken' hook. This is to protect against errors when using this hook in a non-browser environment where 'document' is not defined. --- packages/shared/src/hooks/use-csrf-token.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/shared/src/hooks/use-csrf-token.ts b/packages/shared/src/hooks/use-csrf-token.ts index c852d16f0..3ad8faa0c 100644 --- a/packages/shared/src/hooks/use-csrf-token.ts +++ b/packages/shared/src/hooks/use-csrf-token.ts @@ -3,6 +3,10 @@ * @returns The CSRF token. */ export function useCsrfToken() { + if (typeof document === 'undefined') { + return ''; + } + const meta = document.querySelector('meta[name="csrf-token"]'); if (!meta) {