B2B-88: add starter kit structure and elements
This commit is contained in:
1
packages/shared/src/hooks/index.ts
Normal file
1
packages/shared/src/hooks/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './use-csrf-token';
|
||||
17
packages/shared/src/hooks/use-csrf-token.ts
Normal file
17
packages/shared/src/hooks/use-csrf-token.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Get the CSRF token from the meta tag.
|
||||
* @returns The CSRF token.
|
||||
*/
|
||||
export function useCsrfToken() {
|
||||
if (typeof document === 'undefined') {
|
||||
return '';
|
||||
}
|
||||
|
||||
const meta = document.querySelector('meta[name="csrf-token"]');
|
||||
|
||||
if (!meta) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return meta.getAttribute('content') ?? '';
|
||||
}
|
||||
Reference in New Issue
Block a user