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:
@@ -3,6 +3,10 @@
|
|||||||
* @returns The CSRF token.
|
* @returns The CSRF token.
|
||||||
*/
|
*/
|
||||||
export function useCsrfToken() {
|
export function useCsrfToken() {
|
||||||
|
if (typeof document === 'undefined') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
const meta = document.querySelector('meta[name="csrf-token"]');
|
const meta = document.querySelector('meta[name="csrf-token"]');
|
||||||
|
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
|
|||||||
Reference in New Issue
Block a user