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.
This commit is contained in:
giancarlo
2024-05-20 12:12:07 +07:00
parent 912995730b
commit e4d4069aa8

View File

@@ -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) {